JSON with Ajax - JSON (JavaScript Object Notation)

How to encode and decode using JSON with Ajax?

To create asynchronous web applications, AJAX and XML used on the client side as a group of interrelated web development techniques. You can send and retrieve data from a server asynchronously without interfering with the display and the behavior of the existing page.
Developers of several programming languages are using JSON to pass AJAX updates between the client and the server. Many websites are updating live sports scores as an example of AJAX. If these scores have to be updated on the website, then they must be stored on the server so that the webpage can retrieve the score when it is required. So this is where we can make use of JSON formatted data.
If you update any data with AJAX can be stored using the JSON format on the web server. As we know that AJAX can be used to retrieve these JSON files when necessary, parse them, and perform one of the following operations with javascript. −
  • Store the parsed values in the variables for further processing before displaying them on the webpage.
  • It directly assigns the data to the DOM elements in the webpage, so that they are displayed on the website.

Example

You can save the following code as ajax.htmfile. Here the loading function loadJSON() is used asynchronously to upload JSON data.
Given below is the input file data.json, having data in JSON format which will be uploaded asynchronously when we click the Update Detail button. This file is being kept in http://wisdomjobs.com/json/
The above HTML code will generate the following screen, where you can check AJAX in action −

Cricketer Details

Name

Country

Sachin

India

Update Details:
If you click on the Update Detail button, then you will get following result. You can try JSON with AJAXyourself, provided your browser supports Javascript.

Cricketer Details

Name

Country

Brett

Australia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JSON (JavaScript Object Notation) Topics