当前位置: 代码迷 >> Ajax >> 含有字符串键的数组 怎样 post
  详细解决方案

含有字符串键的数组 怎样 post

热度:453   发布时间:2013-03-01 18:33:02.0
带有字符串键的数组 怎样 post

var data={}, arry=[];
for ( o in data){  arry.push(o,data[o]); }
var postdata = {'arry[]':arry, 'mail' :email};
$.post('up.php', postdata)


以上可以,但是以下就不行:

var data={}, arry=[];
for ( o in data){  arry[o]=data[o]); }   //  带有字符串键的数组  怎样 post
var postdata = {'arry[]':arry, 'mail' :email};
$.post('up.php', postdata)


请问咋回事呢?

------解决方案--------------------
数组的key只能是数字,
用下面那样吧
var postdata = {'arry[]':JSON.stringify(data), 'mail' :email};
$.post('up.php', postdata)

IE不支持JSON.stringify,LZ可以引入json2.js
  相关解决方案