无法加载资源:服务器在绑定功能中响应状态为500(内部服务器错误)

Har*_*ris 33 javascript jquery javascript-events asp.net-mvc-3

我正在尝试使用ajax发送呼叫,但在Chrome中它出现上升错误,但在Firefox中没有错误.但它仍然无法调用该方法.我试图用萤火虫记录我的电话,但是萤火虫没有电话请求.所以这就是firefox中没有错误的原因.

Index.chshtml代码如下

function onLoad(e) {

    var grid = $(this).data("tGrid");
    //bind to the context menu of the Grid's header
    event.preventDefault();
    $(this).find(".t-grid-header").bind('contextmenu', function (e) {
        //wait for the menu to be generated
        setTimeout(function () {
            // bind to the checkboxes change event. The context menu has ID in the format "GridName" + "_contextmenu"
            $('#globalsearchgrid_contextMenu :checkbox').change(function () {
                debugger;
                var $checkbox = $(this);
                // the checked state will determine if the column has been shown or hidden
                var checked = $(this).is(":checked");
                // get the index and the corresponding column from the Grid's column collection
                var columnIndex = $(this).data("field");

                var request = "{'columnIndex':'" + columnIndex + "'value':'" + checked + "'}";
                $.ajax({
                    type: "POST",
                    url: "../../GlobalSearch/SaveColumnInfo",
                    data: request,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) { },
                    error: function (xhr, status, error) {
                        alert(error.responseTextss);
                    }

                });
            });
        });
    });
}
Run Code Online (Sandbox Code Playgroud)

控制器方法

 public JsonResult SaveColumnInfo(string columnIndex, string value)
    {
        CookieHelper helper=new CookieHelper();
        helper.UpdateCookie(int.Parse(columnIndex), value.ToString());

        return Json("Success");
    }
Run Code Online (Sandbox Code Playgroud)

chrome中出错

    POST http://localhost:3577/GlobalSearch/SaveColumnInfo 500 (Internal Server Error) 
    jQuery.ajaxTransport.send 
    jQuery.extend.ajax 
    (anonymous function) 
    jQuery.event.handle 
    jQuery.event.add.elemData.handle.eventHandle
Run Code Online (Sandbox Code Playgroud)

asa*_*lla 53

500代码通常表示服务器上有错误,而不是代码中的任何错误.一些想法

  • 与服务器开发人员联系以获取更多信息.您无法直接获得更多信息.
  • 验证调用中的参数(值).寻找您认为可能导致服务器进程出现问题的任何内容.这个过程不应该死,应该给你一个更好的代码,但是那里也会发生错误.
  • 可能是间歇性的,就像服务器数据库发生故障一样.可能值得在另一个时间尝试.

  • 花了30分钟才发现:Ajax中的数据名称必须与您在控制器中使用的变量名称相同.如果不指定它像`data:{columnindex:request}` (4认同)
  • 我将 id 的奇特名称更改为“id”,并且我的名称有效。去搞清楚 (2认同)
  • 就我而言,我单击了控制台中显示的错误,即 http://vuela.dev/api/calendar/create 500(内部服务器错误)。单击它,我被带到“网络”选项卡,其中显示了不同的文件、它们的状态、大小以及所有这些内容。然后我单击了一个状态为 500 的文件,它向我显示了错误详细信息,我认为其中有一个构造函数以错误的凭据运行。注意:我使用的是 Laravel 5.4 (2认同)