Query-ajax Load () method (27)

Source: Internet
Author: User
jQuery Load () method

The JQuery load () method is a simple but powerful AJAX method.

The load () method loads the data from the server and puts the returned data into the selected element. Syntax:

$ (selector). Load (url,data,callback);

The required URL parameter specifies the URL that you want to load.

The optional data parameter specifies the collection of query string key/value pairs that are sent with the request.

The optional callback parameter is the function name that is executed after the load () method completes.

Here is the content of the sample file ("Demo_test.txt"):

 

The following example loads the contents of the file "Demo_test.txt" into the specified <div> element: Example

$ ("#div1"). Load ("Demo_test.txt");

Try it yourself.

You can also add the JQuery selector to the URL parameter.

The following example loads the contents of the id= "P1" element in the "Demo_test.txt" file into the specified <div> element: instance

$ ("#div1"). Load ("Demo_test.txt #p1");

Try it yourself.

The optional callback parameter specifies the callback function to be allowed after the load () method completes. The callback function can set different parameters: Responsetxt-Contains the result content when the call succeeds Statustxt-contains the state of the call XHR-contains the XMLHttpRequest object

The following example displays a prompt box after the load () method finishes. If the load () method is successful, the "External content loading succeeded" is displayed. ", and if it fails, an error message is displayed: instance

$ ("button"). Click (function () {
  $ ("#div1"). Load ("Demo_test.txt", function (RESPONSETXT,STATUSTXT,XHR) {
    if ( statustxt== "Success")
      alert ("External content loading succeeded.") ");
    if (statustxt== "error")
      alert ("Error:" +xhr.status+ ":" +xhr.statustext);
  });

Try the jQuery AJAX Reference manual for yourself

For a complete Ajax method reference, please visit our  jquery Ajax reference manual

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.