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
  • 53,206
  • 45
  • 230
  • 366
Prabhash Rawat
  • 441
  • 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
  • 2,017
  • 20
  • 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,374
  • 14
  • 18
0

You should try something like this:

$.ajax({
        type: "post",
        url: "target",
        data: info
    });
Ced
  • 1,301
  • 11
  • 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
  • 2,067
  • 1
  • 16
  • 14