javascript - pareser error while sending data as json to php script using jquery ajax -
i'm sending info sever @ localhost using jquery's $.ajax.
the info json object.
as follows:
javascript
var jso={ "data": { "game_name": "road rash", "cheat": "xyzzyspoon!", "effects": [ { "nitro": true }, { "chain": false } ] } }; function senddata(){ var querystring=json.stringify(jso); $.ajax({ type: "post", url: "/gamers_cheats.php", contenttype: "application/json; charset=utf-8", traditional: true, datatype: 'json', data: querystring, success: function(data){ console.log(data); }, error: function(data,textstatus,jqxhr){ alert("unknown error occured :- \n "+textstatus+"\n error"); console.log("unknown error occured :- \n "+textstatus+"\n error"); } }); } senddata(); and handling info in php file as:
gamers_cheats.php:
<?php var_dump($_post); echo"\n count:- ".count($_post); // demo file ?> but problem $.ajax alerts error: part textstatus parsererror. same happening if didn't utilize json.stringify.
and if lines:
contenttype: "application/json; charset=utf-8", traditional: true, datatype: 'json', were removed request sent sever isn't valid request adds slashes (\) every (") in json object.
like:
\"data\": { \"game_name\": \"road rash\", \"cheat\": \"xyzzyspoon!\", \"effects\": [ { \"nitro\": true }, { \"chain\": false } ] } so gives error while processing on server side. there way send post json info using jquery ajax , handle on server?
and 1 more question, can add together $_post parameters not in json format querystring data: querystring +"&&navigator="+navigator.useragent+"" ? ain't working (this not of import though, curious it).
fyi i'm running iis 7 server php 5.2 , jquery version 1.7.2 json2.js .
hope experts here help me.
removing line 'var querystring=json.stringify(jso);' , passing object jso info may help. seek once.
javascript php jquery ajax json
No comments:
Post a Comment