尝试从MVC控制器获取JSON并获取错误净::: ERR_INCOMPLETE_CHUNKED_ENCODING [英] Trying to get JSON from MVC Controller and getting error net::ERR_INCOMPLETE_CHUNKED_ENCODING
问题描述
我正在尝试从控制器中获取JSON以在jQuery中使用.我有以下代码.当我在浏览器中访问URL时,它返回json,因此我知道控制器正在工作...但是我得到了以下
I am trying to get JSON from my controller to use in jQuery. I have the following code. When I visit the URL in my browser it returns the json so I know that the controller is working... But I get the following
GET http://localhost:52802/Checkout/GetContactById?id = 1 net :: ERR_INCOMPLETE_CHUNKED_ENCODING
GET http://localhost:52802/Checkout/GetContactById?id=1 net::ERR_INCOMPLETE_CHUNKED_ENCODING
客户端jQuery
var theUrl = window.location.origin + '/Checkout/GetContactById?id=' + contactId;
$.ajax({
url: theUrl,
type: "GET",
success: function (result) {
alert("Success");
},
error: function (error) {
alert("Error");
}
});
服务器端控制器
[HttpGet]
public IActionResult GetContactById(int id)
{
Contact contact = this.checkoutDataAccess.GetContactById(id);
return Json(contact);
}
我收到的唯一警报是错误"
The only alert I get is "Error"
经过更多研究,似乎一切都在加载中...但是我遇到了错误
After more research it looks like everything is loading... but I am getting an error
无法加载响应数据
Failed to load response data
在控制台中
.
in the console.
我单步执行了代码,所有工作都在控制器端进行.我不确定它是否正确格式化了JSON,或者我没有正确接收它.无论哪种方式,我都不知道发生了什么.
I stepped through the code and everything works on the controller side. I am not sure if it is not formatting the JSON correct, or if I am not receiving it correctly. Either way I have no idea what is going on.
推荐答案
实际上,由于您输入了alert("Error");,因此您收到的是文本Error. 尝试警报(错误);反而 或尝试使用Firebug调试
Actually you are getting the text Error since you put alert("Error"); Try alert(error); instead Or try debugging using firebug
这篇关于尝试从MVC控制器获取JSON并获取错误净::: ERR_INCOMPLETE_CHUNKED_ENCODING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!