1

I have an array Like

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

And i want to convert in json and send through ajax .

Raptor
  • 51,208
  • 43
  • 217
  • 353
Prabhash Rawat
  • 433
  • 1
  • 4
  • 15

4 Answers4

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

then JSON.stringify(info);

HDT
  • 1,911
  • 18
  • 32
1

Try this:

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){

}

});

Avinash Garg
  • 1,326
  • 13
  • 18
0

You should try something like this:

$.ajax({
        type: "post",
        url: "target",
        data: info
    });
Ced
  • 1,281
  • 9
  • 30
0

You could try like this

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
});
Sandeep Pal
  • 1,937
  • 15
  • 14