Select Chapter ❯
jQuery Tutorial
- jQuery Introduction
- jQuery Selector
- jQuery Traversing
- jQuery Events
- jQuery Get/Set
- jQuery Add/Remove
- jQuery CSS
jQuery Effects
jQuery Ajax
jQuery Ajax Load
It is very easy to load the data with jQuery Ajax by its simple method of load()
Syntax of load()
$(selector).load(URL,data,callback);Code Explanation
- URL:it is used to send and load data from a particular URL.
- data:it is an optional parameter it is used to specify which kind of data you send and load.
- callback:it is an optional parameter it is used to give the function that is executed after the process is complete.
Example of Ajax load()
$("#div1").load("file1.txt");
They are some general callback functions
- responseTxt: contains the resulting content if the call succeeds
- statusTxt: contains the status of the call
- xhr: contains the XMLHttpRequest object
Example of Ajax load() with callback
$("#div1").load("file1.txt"); if(statusTxt=="success") alert("Success!"); if(statusTxt=="error") alert("Error");
jQuery Ajax json
You can also load json data
Syntax of getJSON()
$(selector).getJSON(URL,data,callback);Code Explanation
- URL:it is used to send and load data from a particular URL.
- data:it is an optional parameter it is used to specify which kind of data you send and load.
- callback:it is an optional parameter it is used to give the function that is executed after the process is complete.
Example of Ajax getJSON()
$("#div1").load("file1.json");