AJAX stands for Asynchronous JavaScript and XML, and it is a technique that allows us to load data from the Server without having to refresh the browser page.
If you're unfamiliar with AJAX, I recommend starting with our Ajax Tutorial.
JQuery is a fantastic tool for developing next-generation web apps because it includes many AJAX capabilities.
JQuery AJAX makes it simple to load any static or dynamic data. To complete the task, JQuery provides the load() method.
The load() method has the following simple syntax.
[selector].load( URL, [data], [callback] );
Consider the HTML file below, which includes some JQuery scripting.
Click on the button to load /jquery/result.html file −
Here, load() makes an Ajax request to the /jquery/result.html file at the supplied URL. Following the loading of this file, all of the material will be loaded and tagged with the ID stage. Assume our /jquery/result.html file only contains one HTML line.
The result.html file is loaded when you click the specified button.
In some cases, the Server will respond with a JSON string in response to your request. The JQuery utility function getJSON() parses the returned JSON string and passes it as the first parameter to the callback function for further processing.
The [selector] method of the getJSON() method has a straightforward syntax.
getJSON(URL, [data], [callback]); getJSON(URL, [data], [callback]); getJSON(URL, [
Consider the HTML file below, which includes some JQuery scripting.
Click on the button to load result.json file −
The JQuery utility method getJSON() makes an Ajax request to the result.json file at the supplied URL. After loading this file, the callback method receives all of the content, which is then populated inside a stage marked with ID. Assuming, this is the outcome. The following json formatted material may be found in the json file: "name": "Zara Ali", "age": "67", "sex": "female"
The json file is read.
Data Transfer to the Server
You often collect user input and send it to the Server for processing. Using the data argument of any available Ajax method, JQuery AJAX made it simple to send collected data to the Server.
This example shows how to send user input to a web server script, which will return the same result, which we will publish.
Enter your name and click on the button:
|