Pass nested object in jquery ajax -
i want pass next nested object in ajax using jquery:
{ "parent_param1" : [ { "sub_param1" : "sub_val1", "sub_param2" : "sub_val2" }, { "sub_param1" : "sub_val1", "sub_param2" : "sub_val2" }, { "sub_param1" : "sub_val1", "sub_param2" : "sub_val2" } ], "parent_param2" : "par_val2", "parent_param3" : "par_val3" }
i'm trying pass next example:
var url = encodedurl; var info = 'above object'; $.ajax({ type:'post', url:url, datatype:'json', data:data, success:function(res){ alert('success'); }, error:function(e){ alert('error'); } });
i'm getting runtime error response. want create sure right way pass nested object in ajax using jquery?
right passing object server, without key. need pass info json string.
console.log(typeof data); //object console.log(typeof json.stringify(data)); //string
in order read info serverside, need pass info object literal key , value. this:
data: { dto: json.stringify(data) },
on serverside, can access object in different ways, depending on language.
php:
$dto = $_post['dto'];
asp.net:
var dto = httpcontext.current.request.form['dto'];
ajax jquery object
No comments:
Post a Comment