Home  >  Article  >  Web Front-end  >  Usage example of load() method of ajax in jQuery_jquery

Usage example of load() method of ajax in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:24:091019browse

The example in this article describes the usage of the load() method of ajax in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This function is a simple yet powerful ajax method in jQuery.
It loads content from the server and then writes matching elements.
Grammar structure:

Copy code The code is as follows:
$(selector).load(URL,data,callback);

Parameter analysis:

1.selector: A selector that can load content into the element matched by this selector.
2. URL: required, a url address that needs to be loaded.
3.data: Optional, a collection of query string key/value pairs sent with the request.
4. callback: Optional, the function to be executed after the load() function is completed, that is, a callback function.

Code example:

Copy code The code is as follows:






Script Home








The above code implements our requirements and can write the content in the text file into the div element.

callback function:

The callback function can have three parameters. The following describes the functions of the three parameters:

1.responseTxt: Contains the result content when the call is successful.
2.statusTXT: Contains the status of the call.
3.xhr:XMLHttpRequest object.

Code example:

Copy code The code is as follows:






Script Home








The above code implementation can pop up an error message because the path is incorrect and the file cannot be found.

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn