jquery is really a nice lightweight JS framework that can help us quickly develop JS applications and, to some extent, change our habit of writing JavaScript code.
Cut the crap, go straight to the point, let's take a look at some simple methods that encapsulate the Jquery.ajax () to make it easier for us to use, and of course, if you want to deal with complex logic, you need to use Jquery.ajax ().
1. Load (URL, [data], [callback]): Loads the remote HTML file code and inserts it into the DOM.
URL (String): The URL address of the requested HTML page.
Data (MAP): (optional parameters) sent to the server's key/value.
Callback (callback): (optional parameter) a callback function that does not need to be success when the request completes.
This method is passed by default using Get method, and is automatically converted to post if the [data] parameter is passed in. In JQuery 1.2, you can specify a selector to filter the loaded HTML document, and only the filtered HTML code will be inserted into the DOM. Syntax is like "URL #some > selector".
This method makes it easy to dynamically load some HTML files, such as forms.
Sample code:
$ (". Ajax.load"). Load ("http://www.cnblogs.com/QLeelulu/archive/2008/03/30/1130270.html. Post", Function ( ResponseText, Textstatus, XMLHttpRequest) {this;//Here This refers to the current DOM object, that is $ (". Ajax.load") [0]//alert (responsetext); Request returned content//alert (textstatus);//Request Status: Success,error//alert (XMLHttpRequest);//xmlhttprequest object});
The results are displayed here.
Note: Do not know why the URL write absolute path under FF will be wrong, know the trouble to tell. The following get () and post () examples use an absolute path, so you will go wrong under FF and you will not see the results returned. The Get () and post () examples are called across domains, and they are found to be not able to get results, so the run button is removed.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.