开发者

AJAX / History - When is the right time to call the `pushState` method in AJAX app?

开发者 https://www.devze.com 2023-03-20 19:28 出处:网络
I\'m working with AJAX and history object (with the .pushState method). I just want to know when is the right time to call pushState method? Is it before request? after request? or on what state of XM

I'm working with AJAX and history object (with the .pushState method). I just want to know when is the right time to call pushState method? Is it before request? after request? or on what state of XMLHttpRequest's readyState should I call it? As much as possible, I want it to behave like a normal requ开发者_StackOverflowest (without AJAX).


Only HTTP 200's normally get added to a browsers history. So it probably makes sense to do

readyState == 4 && status == 200

That way if your Ajax call has a 404 error for some reason it won't be added to history just like in normal browsing.

0

精彩评论

暂无评论...
验证码 换一张
取 消