Return Multiple Values from AJAX script with ease
This post is not for Expert users. Only the novice guys who are interested in these stuff, might have a look.
Array ( [first_name] => Bibhas [middle_name] => Chandra [last_name] => Debnath )Now,we're gonna encode this data as JSON object. For that,
$json_name=json_encode($array_name);Now your array will look like -
var jsonText = httpObject.responseTextNow we need to transform this JSONText to a JSON Object. For that, we can use the eval() function. Like-
var jsonObject= eval('('+jsonText+')');or
eval('jsonObject='+jsonText);both works the same in this case. So now that we have a JSON Object, lets get those data.
var firstName=jsonObject.first_name; var middleName=jsonObject.middle_name; var lastName=jsonObject.last_name;And that's it, you've got your data back. :)