Home >>jQuery Tutorial >jQuery load() Method

jQuery load() Method

jQuery load() Method

jQuery load() method in jQuery is used to loads data from a server and place the returned data into the selected element.

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

Parameter Values

Parameter Description
url It is a Required parameter and used to Specifies the URL you wish to load
data It is an Optional parameter and used to specifies data to send to the server along with the request
function(response,status,xhr) It is an Optional parameter and used to Specifies a callback function to run when the load() method is completed.
Additional parameters:
  • response – Used to contains the result data from the request
  • status – Used to contains the status of the request ("success", "notmodified", "error", "timeout", or "parsererror")
  • xhr – Used to contains the XMLHttpRequest object
Here is an Example of jQuery load() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("#div1").load("demo_test.txt");
});
});
</script>
</head>
<body>
<div id="div1"><h2>Change This Text</h2></div>
<button class="btn1">Click me to Get External Content</button>
</body>
</html>

Output:

Change This Text


No Sidebar ads