Home  >  Article  >  Web Front-end  >  What are the applicable scenarios for ajax? What are the scenarios where ajax is not applicable?

What are the applicable scenarios for ajax? What are the scenarios where ajax is not applicable?

寻∝梦
寻∝梦Original
2018-09-10 16:11:111435browse

This article mainly introduces to you the usage scenarios of ajax and the inapplicable scenarios of ajax, letting us know where ajax should be used. Now let’s read this article together

Ajax applicable scenarios
1. Form-driven interaction
Traditional form submission, after entering content in the text box, click the button and process it in the background After completion, refresh the page, and then go back to check whether the refresh result is correct. Using Ajax, after clicking the sunmit button, asynchronous processing is performed immediately, and the updated results are quickly displayed on the page. There is no problem of refreshing the entire page.
2. Deep tree navigation
Traversing a deep cascading menu (tree) is a very complex task, and JavaScript is used to control the display. Logic, using Ajax to delay loading deeper data can effectively reduce the load on the server.
Most of our previous processing of cascading menus was like this:
In order to avoid reloading the page caused by each operation on the menu, we do not use it every time. Instead of calling the background, all the data of the cascading menu is read out and written into the array at once, and then JavaScript is used to control the presentation of its subset of items according to the user's operations. This solves the problem of operation response speed, It does not reload the page and avoids the problem of frequently sending requests to the server. However, if the user does not operate the menu or only operates part of the menu, part of the read data will become redundant data and waste the user's time. resources, especially when the menu structure is complex and the amount of data is large (for example, the menu has There are many levels, and each level has hundreds of items), this disadvantage is even more prominent.
If Ajax is applied in this case, the result will be improved:
When initializing the page, we only read out all the data of its first level And it shows that when the user operates one of the first-level menu items, all data of the second-level submenu to which the current first-level item belongs will be requested to the background through Ajax. If the user continues to request an item in the second-level menu that has been presented, Then request all the data of all third-level menus corresponding to the operated second-level menu item from the back, and so on... In this way, you can get what you use and how much you use. How much, there will be no redundancy and waste of data, reducing the total amount of data downloads, and when updating the page, there is no need to reload the entire content, only the part that needs to be updated, which is shorter than the background processing and reloading method. It reduces user waiting time and minimizes waste of resources.
3. Fast user-to-user communication response
In a communication and discussion scenario involving many people, the most unpleasant thing is to let users repeat it over and over again Refresh the page to see if new discussions appear. New replies should be displayed as quickly as possible, and to free users from distracting refreshes, Ajax is the best choice.
4. Insignificant scenarios such as voting, yes/no etc.
For scenarios like this, if the submission process takes 40 seconds, many users will Just ignore it without participating, but Ajax can control the time within 1 second, so more users will join in.
 5. Scenarios for filtering data and manipulating related data
Use filters on data, sort by time, or by time and name, switch filters on and off, etc. Any situation that requires highly interactive data manipulation should be done using JavaScript rather than a series of server requests. After each data update, it takes a lot of time to find and process it, and Ajax can speed up this process. (If you want to see more, go to the PHP Chinese website AJAX Development Manual column to learn)

6. Ordinary text input prompts and automatic completion scenarios
Giving input prompts or automatic completion in input forms such as text boxes can effectively improve the user experience. Especially in situations where the automatically completed data may come from the server side, Ajax is a good choice.
Scenarios where Ajax is not applicable
1. Some simple forms
Although form submission can gain the greatest benefit from Ajax, one Simple comment forms rarely benefit significantly from Ajax. For some less-used form submissions, Ajax can't help much.
2. Search
Some search engines that use Ajax, such as Start.com and Live.com, do not allow you to use the browser's back button to view the results of the previous search. As a result, this is inexcusable to users who have developed search habits.
Now Dojo solves this problem through iframe.
3. Basic Navigation
Using Ajax for site navigation is a bad idea. Why not spend your time making the system program better? Woolen cloth?
4. Replace a large amount of text
Using Ajax can achieve partial refresh of the page, but if every part of the page has changed, why not redo the server? What about requests?
5. Manipulation of presentation
Ajax looks like a pure UI technology, but in fact it is not. It is actually a technology for data synchronization, manipulation and transmission. For clean and maintainable web applications, it's a good idea not to use Ajax to control page rendering. JavaScript can easily process XHMTL/HTML/DOM, and data display can be well expressed using CSS rules.

Problems
1. Ajax engine made with JavaScript, JavaScript compatibility and DeBug are both headaches;
2. Ajax's non-refresh reload, because the page changes are not as obvious as refresh reload, so it is easy to cause trouble to users?D?DUsers are not sure whether the current data is new or has been updated; existing data Solutions include: prompting at relevant locations, designing the data update area to be more obvious, prompting the user after the data is updated, etc.;
 3. The intermediate process cannot be bookmarked. Solution: GoogleMaps solves this problem by providing a "link to this page" on the page. In addition, it can also be solved by adding an invalid ?^ tag to the url link, but it has not been verified yet. I think there is a boss in the IBM developer forum who can't remember the name who said it well. It is a better choice to use it in conjunction with the existing mature presentation layer framework of j2ee. Using it as needed won't cut you off a lot of options. If you try blindly, there may be bitter consequences waiting to tempt you, stimulate you, and lead you to lose your mind. This article ends here (if you want to see more, go to the PHP Chinese website AJAX User Manual column to learn). If you have any questions, you can leave a message below.

The above is the detailed content of What are the applicable scenarios for ajax? What are the scenarios where ajax is not applicable?. For more information, please follow other related articles on the PHP Chinese website!

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