Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

jQuery load() Method

❮ jQuery AJAX Methods

Example

Load the content of the file "demo_test.txt" into a specific <div> element:

$("button").click(function(){
  $("#div1").load("demo_test.txt");
});
Try it Yourself »

Definition and Usage

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

Note: There is also a jQuery Event method called load. Which one is called, depends on the parameters.


Syntax

$(selector).load(url,data,function(response,status,xhr))

Parameter Description
url Required. Specifies the URL you wish to load
data Optional. Specifies 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 is completed.

Additional parameters:
  • response - contains the result data from the request
  • status - contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr - contains the XMLHttpRequest object

Try it Yourself - Examples

Make an AJAX request, and send data with the request
How to use the data parameter to send data with the AJAX request (this example uses the an example explained in our AJAX Tutorial)

Make an AJAX request and use a callback function
How to use the function parameter to work with the data result from the AJAX request.

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


❮ jQuery AJAX Methods