繁体   English   中英

当我尝试在jQuery ajax中发布json时出现内部服务器错误500

[英]I have internal server error 500 when I tried to post json in Jquery ajax

当我尝试发送JSON JSON.stringify(coords); 或以上代码,我会收到错误消息,但是我尝试在数据为空时使用数据: 我怎么解决这个问题?

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

网络方法

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

您只能在服务器端进行调试,因为仅在服务器端会引发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);
        }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM