php-tutorialmade

Learn how to Parse JSON data with jQuery

In this tutorial you are going to see, how to parse JSON data that is coming from a PHP file in jQuery.

If you already know how to read data from a PHP file using jQuery AJAX, it will be the same concept with an extra jQuery function called $.parseJSON()

First, we create a PHP file to print a sample JSON result (data.php).

The output of the above PHP code will be a JSON result like below:

And, here is the second PHP file with jQuery Ajax function which will execute the data.php and print result:

Read the comments in the above script to understand it.

In the above script $.get method is used to call data.php and $.parseJSON() to parse the JSON result. See line no. 13, parsing the data, and from the line no. 16 to 20, using the appropriate keys to print the values.

Here is the online demo of this example:

demo

 

Related Posts

Leave a Reply