Ajax implementations in jquery are categorized in many ways, such as: Load, Jquery.get, Jquery.post, Jquery.getscript, jquery Ajax events, Jquery.ajaxsetup and so on, the previous several for the most commonly used jquery Ajax methods.
Web site development, Ajax is a very convenient tool, it has the same function as the form to complete the front-end and the background interaction! It functions as a local refresh! So when do you use Ajax? Here are a few examples, first should be divided into two categories:
One, in the use of forms and Ajax can complete a function, just use Ajax more quickly and conveniently.
1, use ajax! in the comments below the website article It uses Ajax to upload content to the background when the user submits a comment, and transmits it to the page using JS in the background data. This process is just refreshing the page of the comment module, the article and other content does not refresh, this is not faster than the speed of the form of a lot of it?
2, local paging can use Ajax, such as when the article commented more when we need pagination then we can use Ajax, as the above reason he only refreshed the comments on the page and did not refresh the article so as to improve the speed!
Second, some functional forms can not be implemented, only use ajax!
1, we look at the following search function
If I use the form to submit a search for information on the product, then the data transfer out! That would create a problem, that is, users can not return to the original page when refreshing or keep your search for the product page, this only with Ajax to complete!
2, when the user registration to verify the existence of the user name! This is to get the user mouse left the registration box after the event to submit the user's account to the background verification, and then return to the foreground information according to the checksum, this form can not be done! Of course, you can be in the user to submit all the registration information and then check, so you can use the form but the user experience is not good!
3, we can use Ajax to replace the IFRAME frame! This is very simple, not much to say!
Finally, there are a few things to be aware of when using Ajax:
First, how to convert PHP data to JS array you can look at my other article, the PHP array to the JS array, JS How to receive the PHP array, JSON usage
Second, when you add or modify content on the page with Ajax, the normal jquery method of getting the object is invalid, and you can use the live () or on () method, jquery Gets the dynamically added elements, the difference between live and on.
The above content is a small series through an example to introduce the Ajax when to use, where the specific content, I hope you like.