我已经看到了几个与此相关的主题,并且已经尝试了所有答案( ASP.NET MVC JsonResult返回500 )
I've seen several threads about this, and I've tried all the answers (ASP.NET MVC JsonResult return 500)
我的ajax请求重新返回500 Internal Error.如果我进行调试,我什至无法采取行动.
My ajax request is re-turning a 500 Internal Error. If I debug I never even get to my action.
这是我的ajax调用:
Here is my ajax call:
$.ajax({ url: '@Url.Action("UpdateSortOrder", "FormItems")', data: { itemToUpdateId: item.attr("id"), newParentItemId: parentItemId, newPreviousItemId: previousItemId }, type: 'POST', success: function (data) { console.log(data); }, error: function (xhr, status, exception) { console.log("Error: " + exception + ", Status: " + status); } });我的动作
[HttpPost] public ActionResult UpdateSortOrder(Guid itemToUpdateId, Guid newParentItemId, Guid newPreviousItemId) { FormItem updatedItem = _formItemService.GetOne(x => x.Id == itemToUpdateId); return Json(updatedItem, JsonRequestBehavior.DenyGet); }使用chrome控制台,这些是回复中的响应标头:
Using chrome console, these are the response headers from the reply:
HTTP/1.1 500内部服务器错误 缓存控制:私有 内容类型:text/html;字符集= utf-8 伺服器:Microsoft-IIS/7.5 X-AspNetMvc版本:3.0 X-AspNet版本:4.0.30319 X-Powered-by:ASP.NET 日期:2012年12月18日,星期二21:53:41 GMT 内容长度:17041
HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNetMvc-Version: 3.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Tue, 18 Dec 2012 21:53:41 GMT Content-Length: 17041
服务器日志未显示任何子状态代码.知道我在这里做错了吗?我更喜欢使用POST而不是GET.
Server logs show no substatus codes. Any idea what I am doing wrong here? I've prefer to use POST instead of GET.
表单数据显示为:
itemToUpdateId:18ac5399-342e-4a39-9da1-3281a89501df
itemToUpdateId:18ac5399-342e-4a39-9da1-3281a89501df
newParentItemId:null
newParentItemId:null
newPreviousItemId:null
newPreviousItemId:null
那是正确的.
我已经尝试将contentType设置为application/json和Traditional = true,如以下问题所示:使用"application/json; charset = utf-8";从Web开发人员服务器返回错误500
I've tried setting the contentType to application/json and traditional = true like in this question: Sending ajax post to mvc with "application/json; charset=utf-8" returns error 500 from vs web developer server
相同的错误.
推荐答案好了,我能够弄清楚问题出在哪里,我的AJAX语法甚至操作都没有错.只是我返回的对象包含一个循环引用.通过单击网络"标签下的POST请求,然后查看预览"标签,我可以看到chrome控制台中的实际错误.这显示了实际的错误消息.
Well I was able to figure out what the problem was, there was nothing wrong with my AJAX syntax, or even the action. It was just that my returned object contained a circular reference. I was able to see the actual error in chrome console by clicking on the POST request under Network tab, then viewing the preview tab. This displayed the actual error message.
更多推荐
Ajax请求使用MVC和$ .ajax调用与POST一起返回HTTP错误500?
发布评论