javascript - Can not handle the json response from php -


this question has answer here:

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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -