Reference: jQuery load method

Load HTML from the server and place it into an element.

Parameters

  1. URL - The URL of the HTML to get from the server.
  2. data - Optional JSON Object containing key / value pairs to send with the request.
  3. calback - Optional function that is called when the request is complete.

Callback

The callback has the following parameters:

  1. responseText - The HTML returned from the server if the request succeeds.
  2. textStatus - The status of the response.
  3. 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);
  }
});
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License