当我尝试发送json jQuery时,我有内部服务器错误500 ajax

问题描述:

当我尝试发送json JSON.stringify(coords);或上面的代码我得到的错误消息,但我试着当数据是空的像数据:{}代码正常工作。我怎么解决这个问题?当我尝试发送json jQuery时,我有内部服务器错误500 ajax

$.ajax({ 
    type: "POST", 
    data: {"yagiz":"aabb"}, 
    dataType: 'json', 
    url: url, 
    crossDomain:true, 
    async: false, 
    contentType: "application/json; charset=utf-8", 
    success: function (response) { 
     $("#Content").text(response.d); 
     console.log(response.d); 
    }, 
    failure: function (response) { 
     alert(response.d); 
     console.log(response.d); 
    } 
}); 

Web方法

[System.Web.Services.WebMethod] 
public static string GetLocationPolygon(string location) 
{ 
    return location; 
} 
+4

500错误意味着错误是在服务器上,而不是你的JS。没有看到服务器端代码,或者至少是网络控制台的错误,我们无法帮助您。 –

+0

您需要知道Web API(您要发送请求的URL)是如何工作的,以便了解它是如何得到内部服务器错误的。 –

+0

[System.Web.Services.WebMethod] public static string GetLocationPolygon(string location) { 返回位置; } – ygzmglkc

您可以在服务器端的调试只能在服务器端引发500内部错误。您可以捕获并记录确切的异常。

试试这个代码

$.ajax({ 
     type: "POST", 
     data: JSON.stringify({"location":"aabb"}), //Change here 
     dataType: 'json', 
     url: url, 
     crossDomain:true, 
     async: false, 
     contentType: "application/json; charset=utf-8", 
     success: function (response) { 
      $("#Content").text(response.d); 
      console.log(response.d); 
     }, 
     failure: function (response) { 
      alert(response.d); 
      console.log(response.d); 
     } 
    });