Skip to content Skip to sidebar Skip to footer

Store Each Value Of A AJAX Query Result To Javascript Variables

Here's a jQuery-ajax function that returns some data from a php file. $('.up').click(function() { var act = $('.active').val(); $.ajax({ type: 'POST', url:

Solution 1:

I am assuming you are going to do something with this data so you'll need to know what you are looking for.

Get your PHP to serve up JSON with keys like so:

{"Bob": "24", "Sue": "12"}

This way you can access the information you need or just loop through the whole lot. I've made a little fiddle which I am hoping will help you understand.

Ultimately you simply want to use the jQuery $.getJSON to pull the information and then deal with it however you please.

http://jsfiddle.net/PgVkL/

If you need PHP to output in the format you specified then you can do:

$people = array("24", "12", "16", "48");
var_dump(json_encode($people));

Here's the docs: http://uk3.php.net/json_encode


Post a Comment for "Store Each Value Of A AJAX Query Result To Javascript Variables"