【问题标题】:passing an array of hash to server with jquery使用 jquery 将哈希数组传递给服务器
【发布时间】:2011-05-09 20:03:32
【问题描述】:

我有一个这样的数组

places = new Array();
places.push({name: "ci", loc: "bo"})
places.push({name: "ae", loc: "ea"})

if i try to send this data to server with this:
jQuery.ajax({type: "POST", url: "import", 
              data: { "places[]": places, kind: "pub" }, 

            });

不起作用。 我收到一个 javascript 对象数组

我该怎么办?

谢谢

【问题讨论】:

    标签: jquery ajax arrays hash


    【解决方案1】:

    您可以将数组转换为 JSON 字符串:

    jQuery.ajax({type: "POST", 
                 url: "import", 
                 data: {places: JSON.stringify(places), kind: "pub" }
                });
    

    然后在服务器端解码字符串。如果你使用 PHP,它会是json_decode:

    $places = json_decode($_POST['places'], true);
    

    【讨论】:

      猜你喜欢
      • 2013-09-27
      • 1970-01-01
      • 2013-09-04
      • 2012-05-18
      • 2016-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      相关资源
      最近更新 更多