Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

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

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.