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

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH

Check Out SEMRUSH