![](/img/trans.png)
[英]Jquery ajax call wont access the controller: Failed to load resource: the server responded with a status of 500 (Internal Server Error)
[英]Ajax call not hitting the controller action method, status 500 , Internal Server Error
我對控制器操作方法的ajax調用未擊中控制器,它在兩者之間中斷。 它說xhr.status = 500
, response text = Internal Server Error
相同的代碼在其他項目中也可以正常工作。
JavaScript代碼
ajaxCall: function (data, url, success, error, noShow) {
// make sure that there is never an empty POST body to protect against proxy allowing too soon
if (!data) {
data = "{'dummy':1}";
}
var reqData = data;
$.ajax({
type: "POST",
traditional: true,
url: url,
data: data,
// switch on/off geenraic AJAX events bound globally
/** @default false
*/
global: !(noShow || false),
cache: false,
dataType: "json",
// add CSRF token to each request
beforeSend: function (xhr) { /* jquery 1.5.* use headers */
var csrf_token = $("[name=__RequestVerificationToken]").val();
xhr.setRequestHeader('__RequestVerificationToken', csrf_token);
},
contentType: "application/json",
success: function (data) {
success(data);
},
error: function (a, b, c) {
// repeat ajax call when "Empty body element" message gets returned. It means that proxy challenge was completed too soon.
if (a.responseText == "EmptyBodyElement")
Service.ajaxCall(reqData, url, success, error);
else {
if (error)
error(a, b, c);
else
Service.responseError(a, b, c);
}
}
});
},
我在jQuery 1.9.1中收到錯誤
if ( callback && ( isAbort || xhr.readyState === 4 ) )
xhr.status = 500
, xhr.responsetext = Internal Server Error
在其他項目中使用相同的代碼,我已經檢查了所有記錄。
控制器動作方式
[使用AllowAnonymous]
公共ActionResult CheckUserStatus(字符串UserId,bool NewUserStatusCheck)
{
}
斷點沒有達到
Xhr.responstext =“內部服務器錯誤”
我有一個類似的問題。
這是我的錯誤代碼。
JQUERY代碼
$.ajax({
url: "@Url.Action("AllocateByCapacity","BookScenario")",
dataType: 'json',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({'scenarioId':JSON.stringify(PlanningBookHandler.getScenarioId())
}),
success: function (response) {
SCP.Utils.showMessageDialog("Records Updated");
},
error: function () {
SCP.Utils.showMessageDialog("Records UpdateFailed");
}
});
控制器動作方法代碼
public ActionResult AllocateByCapacity(int scenarioId)
{
return Json(new object());
}
就我而言,您可以看到我正在將字符串值傳遞給需要整數參數的操作方法。 那就是我在代碼中發現的錯誤。 將參數更改為整數值后,代碼工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.