我正在尝试使用 Ajax 发送呼叫,但在 Chrome 中出现错误,但在 Firefox 中没有错误。但它仍然无法调用该方法。我试图在 Firebug 中记录我的通话,但 Firebug 中没有通话请求。所以这就是 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);
}
});
});
});
});
}
控制器方法
public JsonResult SaveColumnInfo(string columnIndex, string value)
{
CookieHelper helper=new CookieHelper();
helper.UpdateCookie(int.Parse(columnIndex), value.ToString());
return Json("Success");
}
Chrome 中的错误
POST http://localhost:3577/GlobalSearch/SaveColumnInfo 500(内部服务器错误)
jQuery.ajaxTransport.send
jQuery.extend.ajax
(匿名函数)
jQuery.event.handle
jQuery.event.add.elemData.handle.eventHandle