jQuery 加载资源失败:服务器在绑定函数中响应状态为 500(内部服务器错误)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19180684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:23:02  来源:igfitidea点击:

Failed to load resource: the server responded with a status of 500 (Internal Server Error) in Bind function

javascriptasp.net-mvc-3jqueryjavascript-events

提问by Haris

I'm trying to send a call using ajax but in Chrome it is rising error but in firefox there is no error. But still it can't calling the method. I tried to record my call in firebug but there is no call request in firebug. So that's the reason there is no error in firefox.

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

Index.chshtmlcode is below

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);
                    }

                });
            });
        });
    });
}

Controller method

控制器方法

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

        return Json("Success");
    }

Error in 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

回答by asantaballa

The 500 code would normally indicate an error on the server, not anything with your code. Some thoughts

500 代码通常表示服务器上的错误,而不是您的代码的任何内容。一些想法

  • Talk to the server developer for more info. You can't get more info directly.
  • Verify your arguments into the call (values). Look for anything you might think could cause a problem for the server process. The process should not die and should return you a better code, but bugs happen there also.
  • Could be intermittent, like if the server database goes down. May be worth trying at another time.
  • 与服务器开发人员联系以获取更多信息。您无法直接获得更多信息。
  • 验证您在调用中的参数(值)。查找您认为可能会导致服务器进程出现问题的任何内容。这个过程不应该死,应该返回一个更好的代码,但错误也会发生。
  • 可能是间歇性的,就像服务器数据库出现故障一样。可能值得在其他时间尝试。