jQuery load() Method

tutorial and example
tutorial and example

jQuery load() method is a powerful AJAX method used for loading data asynchronously.

The load() method loads HTML or text content from a server and added into a DOM element.

Syntax:

Here is “demo_test.txt” file content:

Example:

Try Now

The callback optional parameter is the name of a function to be executed when load() method is completed. The parameter of callback is different:

responseTxt: If the call succeeds then it contains the resulting content.

statusTxt: statusTxt is used to contain the status of the call.

xhr: xhr is used to contain the XMLHttpRequest object.

In the following example if the load() method completes then an alert box displays.

It displays “External content loaded successfully!” message if the load() method succeeds and if it fails then it displays an error message.

Example:

Try Now