Should I wait for ajax to complete the page redirection?

I know how to wait for ajax to complete, but if I am going to redirect the page after some ajax calls have been launched, should I wait for them to complete before the redirect? Does it matter?

+6
source share
3 answers

If you are sure that the ajax call will succeed, then after the ajax call the redirect will not affect it as much as your server. But do not forget that the client may lose the connection or some errors may occur, so you may have to wait to make sure the calls are successful. Another thing to keep in mind is whether your ajax calls will affect any page you're about to redirect to. In this case, DEFINITELY wait before redirecting. You do not want your user to be redirected to a broken page because their connection was slow or your server had hiccups.

+5
source

I recommend waiting and handling possible errors that may occur.

You get a secure connection, error detection, the best software, performing the entire process synchronously, making redirects at the end.

You can spend another 0.1 seconds to execute, but who needs it?

+1
source

I would say that Ajax followed by a redirect is not a good option for Ajax. Instead, I would recommend doing a normal server request and then taking care of all the operations on the server before redirecting to the final destination.

This will result in a simpler circuit and significant network traffic. I recommend using Ajax in cases where you want to avoid reloading the page. However, in your scenario, you plan to leave the page as soon as your operations are complete, so why not avoid what Ajax will give you.

+1
source

Source: https://habr.com/ru/post/949792/


All Articles