Ajax请求使用MVC和$ .ajax调用与POST一起返回HTTP错误500? [英] Ajax Request returns HTTP error 500, using MVC and $.ajax call with POST?

查看:323
本文介绍了Ajax请求使用MVC和$ .ajax调用与POST一起返回HTTP错误500?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了几个与此相关的主题,并且已经尝试了所有答案( 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,如以下问题所示:

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆