[英]failed to load resource: the server response with a status 500 (internal server error)
[英]Ajax call with a failed to load resource: the server response with a status 500 (internal server error)
我創建了一個 function 來執行 ajax 調用,但調用它時出現此錯誤。
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
這是代碼:
$('#Item').change(function () {
debugger
$('#Price').empty();
$('#Description').empty();
$('#Quantity').val("");
$('#Amount').val("");
$.ajax({
type: "GET",
url: "/Payments/GetItemByIdForEdit/",
datatype: "Json",
data: { id: $('#Item').val() },
success: function (data) {
debugger
$("#Price").val(data.ItemUnitPrice);
$("#Description").val(data.itemDescription);
//$("#productId").text(value.Id);
}
});
});
這是動作代碼:
public JsonResult GetItemByIdForEdit(string id)
{
if (id != "")
{
int productId = Convert.ToInt32(id);
var product = _unitOfWork.Items.GetItemSingleOrDefault(productId);
return Json(product, JsonRequestBehavior.AllowGet);
}
else
{
var product = new Item();
//product.Description = "";
//product.UnitPrice = 0.0;
return Json(product, JsonRequestBehavior.AllowGet);
}
}
我看不出問題出在哪里?
你有什么解決辦法?
謝謝你
這是調試器模式的結果:
您正在將空值傳遞給控制器。 您必須首先對您的參數進行字符串化。 例子:
var postData = JSON.stringify({
'id': $('#Item').val()
});
$.ajax({
type: "POST",
url: "/Payments/GetItemByIdForEdit/",
datatype: "application/json",
data: postData,
success: function (data) {
debugger
$("#Price").val(data.ItemUnitPrice);
$("#Description").val(data.itemDescription);
//$("#productId").text(value.Id);
}
});
在您的方法中,您可以直接使用 int
public JsonResult GetItemByIdForEdit(int id)
500 代碼通常表示服務器錯誤,而不是您的代碼。 一些想法
與服務器開發人員聯系以獲取更多信息。 您無法直接獲取更多信息。 驗證您的 arguments 是否進入通話(值)。 查找您可能認為可能導致服務器進程出現問題的任何內容。 這個過程不應該死掉並且應該返回一個更好的代碼,但是錯誤也會在那里發生。 可能是間歇性的,例如服務器數據庫出現故障。 可能值得在其他時間嘗試。
同一問題的解決方案之一是重復發布 url。更改發布 URL 並重試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.