【问题标题】:How can I post multi-dimensional array using jquery ajax?如何使用 jquery ajax 发布多维数组?
【发布时间】:2016-03-08 19:08:39
【问题描述】:

我有一个类似{{0,0},{1,1},{2,2}} 的数组,它是一个javascript 变量。我尝试使用 JSON.Stringify 发布它,但它给出了内部服务器错误 500。我该如何发布和使用它?

这是我的 jquery 代码:

 $.ajax({
    type: "POST",
    data: myJsonData,
    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;
    }

【问题讨论】:

  • 如果错误是内部服务器错误,您应该检查您的服务器日志,看看发生了什么故障。
  • 正如@user3663216 所说,您正在使用对象表示法,将您的代码或myJsonData 更改为有效数组。

标签: javascript jquery .net json ajax


【解决方案1】:

[] 是数组,{} 是对象。对象必须有键值对。

也一样..

{0:{0:0},1:{1:1},2:{2:2}}

或

[[0,0],[1,1],[2,2]]

修复它..

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 2014-10-01
    • 2011-12-12
    • 1970-01-01
    • 2013-07-25
    • 2013-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    相关资源
    最近更新 更多