Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery load() method

jQuery load() method

jQuery AJAX methods jQuery AJAX methods

Example

Load the contents of the file "demo_test.txt" into the specified element

element:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

#div1

"

)

.

load

(

"

demo_test.txt

"

)

;

}

)

;

Try it »


Definition and Usage

The load() method loads data from the server and places the returned data into the specified element.

**Note:** There is also a jQuery method named load Eventsmethod. Which one is called depends on the parameters.


Syntax

$(

selector

).load(

url,data,function(response,status,xhr

))

Parameters Description
url Required. Specifies the URL you want to load.
data Optional. Specifies the data to send to the server along with the request.
function(response,status,xhr) Optional. Specifies a callback function to run when the load() method completes.
 额外的参数:       

 
  • response - Contains the resulting data from the request
  • status - Contains the status of the request ("success", "notmodified", "error", "timeout", "parsererror")
  • xhr - Contains the XMLHttpRequest object
  • |

    More examples

    Generate an AJAX request and send data with it
    How to use the data parameter to send data through an AJAX request (this example is explained in our AJAX Tutorial section).

    Generate an AJAX request and use a callback function
    How to use the function parameter to handle the data result from an AJAX request.

    Generate an AJAX request with an error
    How to use the function parameter to handle errors in an AJAX request (using the XMLHttpRequest parameter).


    jQuery AJAX methods jQuery AJAX methods