javascript - Client-side redirect question - Stack Overflow

I am setting up a site now that uses a lot of ajax interactions. The basic flow of what is going on now

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
Add a ment  | 

3 Answers 3

Reset to default 2

What 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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745279608a4620216.html

相关推荐

  • javascript - Client-side redirect question - Stack Overflow

    I am setting up a site now that uses a lot of ajax interactions. The basic flow of what is going on now

    2小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信