javascript - Can not handle the json response from php -
this question has answer here:
- parse json in javascript? [duplicate] 16 answers
i'm using pmxdr library make cross domain call (jquery php , respond in json). problem can not handle response if print on html comes -
{"title":"mr","first_name":"shak","last_name":"mana"}
here code use
pmxdr.request({ uri : "http://xxxx/pmxdr/respons1.php", callback: handleresponse }); function handleresponse(response) { if (!response.error) { // request successful console.log(response.headers["content-type"]) //works console.log(response.data) //works (var key in response.data) { alert(response.data[key]); // gives each character :( } } else print("error: " + response.error); }
on console above mentioned json on alerts each character separate popping out. if use console.log(response.data["title"])
says undefined. please tell me i'm doing wrong.
it because, getting string response, not json object. 1 thing can is, make ajax datatype json.
datatype : json
or can make string json object in client side. can use parsejson method that,
function handleresponse(response) { response=$.parsejson(response); if (!response.error) { // request successful console.log(response.headers["content-type"]) //works console.log(response.data) //works (var key in response.data) { alert(response.data[key]); // gives each character :( } } else print("error: " + response.error); }
Comments
Post a Comment