Javascript examples for jQuery Method and Property:load
The load() method loads data from a server and sets the returned data into the selected element.
$(selector).load(url,data,function(response,status,xhr))
Parameter | Require | Description |
---|---|---|
url | Required. | URL to load |
data | Optional. | data to send to the server along with the request |
function(response,status,xhr) | Optional. | function to run when the load() method is completed. |
Additional parameters:
The following code shows how to load the content of the file "demo_test.txt" into a specific <div> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("demo_test.txt"); });// w w w .java 2 s. com }); </script> </head> <body> <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div> <button>Load</button> </body> </html>