jQuery load()Methods
Example
Load the content of the file "demo_test.txt" into the specified <div> element:
$("button").click(function(){
$("#div1").load("demo_test.txt");
});
Try it Yourself »
Definition and Usage
The load() method loads data from the server and places the returned data into the selected element.
Note:There is also a jQuery named loadeventmethod. 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 need to load. |
| data | Optional. Specifies data to be sent to the server along with the request. |
| function(response,status,xhr) | Optional. Specifies a callback function to run when the load() method is completed. Additional parameters:
|
More Examples
Make an AJAX request and send data through this request
How to use the data parameter to send data through an AJAX request (This example was explained in ourAJAX tutorial).
Make an AJAX request and use a callback function
How to use the function parameter to handle the data result from an AJAX request.
Make an AJAX request with errors
How to use the function parameter to handle errors in an AJAX request (using the XMLHttpRequest parameter).
Other Extensions
jQuery AJAX Methods