This article mainly introduces the load () and post () Methods of ajax in jQuery, and analyzes the load () and post () methods in jQuery in detail using examples () methods To achieve ajax interaction related skills and precautions, you can refer to the example of this article describes the ajax load () and post () methods in jQuery. We will share this with you for your reference. The details are as follows:
I. load () method
The load () method of jQuery ajax can load remote HTML file code and insert it into the DOM. This is a little different from post and get, however, you can quickly load the html of a page during page loading and save it to the dom for execution.
The load () method uses the GET method by default. If the data parameter is passed, the Post method is used.
The POST method is automatically converted when additional parameters are passed. In jQuery 1.2, you can specify a selector to filter loaded HTML documents. In DOM, only filtered HTML code is inserted. The syntax is like "url # some> selector". The default selector is "body> *".
Explanation:
Load is the simplest Ajax function, but its usage has limitations:
1. It is mainly used to directly return HTML Ajax interfaces.
2. load is a jQuery packaging set method. It needs to be called on the jQuery packaging set and will load the returned HTML to the object, even if the callback function is set, it is undeniable that the load interface is cleverly designed and easy to use. the following example shows how to use the Load interface:
Load () function:
Function Introduction: load (url, [data], [callback]) Return Value: jQuery
Parameter description:
Url: the url of the HTML webpage to be loaded.
Data: (optional) key/value data sent to the server.
Callback: (optional) callback function when loading is successful.
The following is an example:
First, create the following test.html file:
Ajax demoScript home (www.jb51.net) provides a large number of scripts and materials for you to download!
After creating the ajax.html file, remember to introduce jquery.