Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

jQuery Ajax Load

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");
PreviousNext

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Subscribe TalkersCode! One Of The Best
Web Development And Review Blog

Get Latest Tutorials And Reviews
Via Email