Reference: jQuery load method
Load HTML from the server and place it into an element.
Parameters
- URL - The URL of the HTML to get from the server.
- data - Optional JSON Object containing key / value pairs to send with the request.
- calback - Optional function that is called when the request is complete.
Callback
The callback has the following parameters:
- responseText - The HTML returned from the server if the request succeeds.
- textStatus - The status of the response.
- jqXHR - XMLHttpRequest object
Syntax
$(selector).load(URL, data, callback);
Example
Get the viewContent.html page from the server and load the contents into the element with an id of "view".
$("#view").load("/viewContent.html");
Example with callback
Get the viewContent.html page from the server and load the contents into the element with an id of "view". If the request fails, then display an alert.
$("#view").load("/viewContent.html", function( response, status, xhr ) { if (status === "error") { alert("Failed to load: " + xhr.status + ": " + xhr.statusText); } });