jQuery load() method is simple but very powerful AJAX method. The Load() method in jQuery helps to load data from server and returned into selected element without loading the whole page.
$(selector).load(URL, data, callback);
Parameters: This method accepts three parameter as mentioned above and described below:
- URL: It is used to specify the URL which need to load.
- data: It is used to specify a set of query key/value pairs to send along with the request.
- callback: It is the optional parameter which is the name of a function to be executed after the load() method is call.
Return Value: This method returns the requested data from server with the specified URL.
The geeks.txt file stored on server and it will load after clicking the click button. The content of geeks.txt are:
There is also an additional callback function in the parameter which will run when the load() method is completed. This callback function has three different parameters:
- parameter 1: It contains the result of the content if the method call succeeds.
- parameter 2: It contains the status of the call function.
- parameter 3: It contains the XMLHttpRequest object.
Output of the given code followed an alert box that will appear after click on the button and if the content loaded successfully then it will give a message “Content loaded successfully!”. Otherwise it will show an error message.
- JQuery | Set focus on a form input text field on page load
- jQuery | last() with Examples
- jQuery | val() with Examples
- jQuery | eq() with Examples
- jQuery | has() with Examples
- jQuery | one() with Examples
- jQuery | first() with Examples
- jQuery | after() with Examples
- jQuery | on() with Examples
- jQuery | insertAfter() with Examples
- jQuery | ready() with Examples
- jQuery | mouseenter() with Examples
- jQuery | mousedown() with Examples
- jQuery | mouseleave() with Examples
- jQuery | prependTo() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.