-2
正在获取statuss 500错误。 当我点击getcustomer按钮'Getcustomers'方法被称为哪些retuns json。在将SqlDataReader序列化为Json之后获取500状态
脚本:
<script>
var MyApp = angular.module("MyApp", []);
MyApp.controller("ctrl", function ($scope, $http) {
$scope.helloAngular = "hello";
$scope.GetCustomers = function() {
debugger;
$http.get("/Home/Getcustomers")
.success(function (data) {
$scope.customerDetails = data;
}).
error(function (data, status, thrownError) {
//alert(status);
//alert(data.responseText);
alert(thrownError);
});
}
});
</script>
服务器端代码: 我从这个函数得到JSON数据:
public ActionResult Getcustomers()
{
string query = "select top 10 * from Customers ";
ArrayList custArray = new ArrayList();
SqlCommand cmd = new SqlCommand(query, sqlcon);
sqlcon.Open();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
custArray.Add(new
{
Name = reader["ContactName"],
City = reader["City"],
PostalCode = reader["PostalCode"],
Country = reader["Country"],
Phone = reader["Phone"],
});
}
var result= JsonConvert.SerializeObject(custArray);
sqlcon.Close();
return Json(result);
}
我有搜索,但不能让我在哪里去wrong.Plz帮我。
500是一个错误至极来自您的服务器。服务器端的日志是什么? –
@Apédémak当我调试它给我的JSON数据,但没有得到为什么它通过500状态 –
好500是“内部服务器错误”。这是关于服务器的。当你说你的JSON很好时,你的代码的一部分是什么?在你的var结果? –