If you use ajax and post at the same time, which one should be executed first? Should the post be executed after ajax returns or at the same time?
If you use ajax and post at the same time, which one should be executed first? Should the post be executed after ajax returns or at the same time?
The speed should be similar, but ajax has advantages in interaction. For example, a traditional post will cause the browser to enter another page. At this time, if the user clicks the refresh button, the browser will submit it again. Another example is the login operation. If the user fails to log in, When being kicked back to the login page, the user has to perform another network request. Using ajax can solve these problems
Traditional post requests will reload the entire page. Although the browser will cache it by default, some resources do not need to be reloaded. However, if you simply consider the speed of transmission, ajax is slightly faster. However, it is not clear whether the ajax post requires some parsing work. , so in fact the difference is not too big. How to do it depends on your needs.
Of course, execute js first and then execute the form event.