Like XML, we can also use Json Formatted data to transfer data between the client and the server asynchronously. It can be used in the web applications that requires live update on the webpage without reloading the webpage for the fresh data such as live score update in sports, stock price live update for a particular stock that changes every second, etc. JSON formatted data is heavily used for such websites in order to make the AJAX calls.
Example on JSON and AJAX call
In the following example, we have written code into json_ajax_demo.html file. Here, we are using the function ‘loadJSONData ()’ which is used asynchronously in order to upload the JSON data.
Also, JSON data file is available over internet at the below URL, we are going to read JSON formatted data from this URL and display it on the AJAX call i.e. on button’s click.
Eduonix JSON Example
House of Lords
When we open the above HTML in a web browser, we can observe the following output on the browser.
Now, click on the “Update Details on Button Click” button, which will trigger the AJAX call via function ‘loadJSONData ()’ and bring JSON data from the URL and render it on the browser as shown below. This is nothing but the working of AJAX over JSON formatted data.
Source code for the uses of JSON Formatted data for the AJAX Call
In this chapter, we discussed about the use of JSON formatted data for the AJAX call and demonstrated the concept with the help of a suitable example.
The post Learn How to Use JSON to Demonstrate an AJAX Call appeared first on Eduonix.com | Blog.