JSON Question.
Posted: Mon May 21, 2007 6:00 pm
How do I have php return a JSON object?
I have:
It returns the right format: {key: value, ...}
What can I do with this on the Javascript side?
Every time I have my request like this:
The lines after "date = eval..." doesn't appear not to execute.
How could I take the response string from PHP and turn it into a JavaScript obj?
Thanks for reading I appreciate some help with this one.
I have:
Code: Select all
while ($rows = mysql_fetch_array($results))
{
foreach($rows as $key=>$val) $arr[] = "\"$key\":$val";
echo '{'.implode(', ', $arr).'}';
}
What can I do with this on the Javascript side?
Every time I have my request like this:
Code: Select all
$.post(location.href,{action: "select",title: $("li.selected").text()},function (data) {
data = eval('('+data+')');
$("#title").removeAttr("disabled");
$("#imageFile").removeAttr("disabled");
$("#artical").removeAttr("disabled");
$("#submit").removeAttr("disabled");
});
How could I take the response string from PHP and turn it into a JavaScript obj?
Thanks for reading I appreciate some help with this one.