admin管理员组文章数量:1417665
I am setting up a site now that uses a lot of ajax interactions. The basic flow of what is going on now is data is validated both client-side and server-side, and if the data is correct the response from and AJAX post will be the url to the next page to go to.
When I receive the url client side I am currently using window.location = url
to perform my redirect.
For some reason, something about this seems incorrect. Specifically, looking through a variety of open-source projects, I rarely see it. I am wondering if the interaction I am describing above is correct, and if it is not, what I could do differently to correct my current design.
I am setting up a site now that uses a lot of ajax interactions. The basic flow of what is going on now is data is validated both client-side and server-side, and if the data is correct the response from and AJAX post will be the url to the next page to go to.
When I receive the url client side I am currently using window.location = url
to perform my redirect.
For some reason, something about this seems incorrect. Specifically, looking through a variety of open-source projects, I rarely see it. I am wondering if the interaction I am describing above is correct, and if it is not, what I could do differently to correct my current design.
Share Improve this question edited Aug 23, 2011 at 0:32 LazyOne 166k48 gold badges414 silver badges415 bronze badges asked Aug 22, 2011 at 17:42 josephmisitijosephmisiti 9,99412 gold badges57 silver badges72 bronze badges 1- There is nothing wrong with this approach – Prisoner ZERO Commented Aug 22, 2011 at 17:54
3 Answers
Reset to default 2What you are doing is pletely fine and is the normal approach that people take. Something to keep in mind is how do you handle failed requests that is your post failed for some reason or there was failure in the ajax request etc.
There was an interesting so question and read the marked answer: How to manage a redirect request after a jQuery Ajax call
Hope this helped
The best way for redirections is from the server side, basically because the server is the one who knows if you can access this page or not and response 302 redirection in the header or just return the page it self, then if the server approve your request for the page the AJAX should handle the interaction in the page without taking concern about the security.
If anyway you don't concern about security then window.location
is fine.
This defeats the whole point of AJAX: avoid loading full pages for every interaction, and thus limit bandwidth usage and be more responsive.
With your design, each interaction needs two requests: one to validate the data, and a second one to load the next full page. You'd better avoid AJAX pletely: it would certainly be more efficient. Why not returning an error response if validation fails, and a success response with what must be displayed after the post if validation succeeds?
本文标签: javascriptClientside redirect questionStack Overflow
版权声明:本文标题:javascript - Client-side redirect question - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745279608a2651361.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论