如何返回Web API数据
这个问题在这里已经有了答案:
C#
[WebMethod]
public string GetEmployeeData(int userId)
{
Dictionary<string, object> returnData = Dictionary<string, object>();
using(SqlConnection conn = new SqlConnection(connString))
{
//etc... etc...
}
var jsonSerializer = new JavaScriptSerializer();
return jsonSerializer.Serialize(returnData);
}
使用Javascript:
$http.post('MyApp/GetEmployeeData', { userId: 1 }).then(function(response){
$scope.myData = response.data;
}).catch(function(response) {
//an error has occurred
});
链接地址: http://www.djcxy.com/p/20417.html