将jquery数组转换为json并通过ajax发送它

时间:2014-12-04 06:53:24

标签: jquery json

我有一个像

的数组
info['mk'] = 'hi';
info['pk'] = 'hello';
info['wk'] = 'hi';
info['rk'] = 'hello';

我想转换为json并通过ajax发送。

4 个答案:

答案 0 :(得分:1)

info = {}; //must be set 
info['mk'] = 'hi';
info['pk'] = 'hello';
info['wk'] = 'hi';
info['rk'] = 'hello';

然后JSON.stringify(info);

答案 1 :(得分:1)

试试这个:

info={}
info['mk'] = 'hi';
info['pk'] = 'hello';
info['wk'] = 'hi';
info['rk'] = 'hello';

$.ajax({
  type: "POST",
  dataType: "json",
  data: JSON.stringify({info:info}),
  url: "",
  success: function(msg){

}

});

答案 2 :(得分:0)

你应该尝试这样的事情:

$.ajax({
        type: "post",
        url: "target",
        data: info
    });

答案 3 :(得分:0)

你可以尝试这样

var info = [];
var tmpObj = {};
info['mk'] = 'hi';
info['pk'] = 'hello';
info['wk'] = 'hi';
info['rk'] = 'hello';
tmpObj.arr = info;
$.ajax({
    type: "post",
    url: "target",
    datatype:"json",
    data: tmpObj
});