jquery-pjax icon indicating copy to clipboard operation
jquery-pjax copied to clipboard

No request on back button

Open jayd3e opened this issue 10 years ago • 6 comments

My interface looks like this. interface_example_one

I'm using two main containers. The first encompasses the entire right side of the page and is called #page. interface_example_two

The second is a subsection of #page and is called #content. interface_example_three

As you would expect, when you click on the left sidebar it replaces the content in #page, whereas if you click on any of the subnav items in #page, it replaces the content in #content. My problem is with the back button functionality under this system. I took a look at the pjax demo, and it appears that when you click the back button, the container gets retained, the content is requested again from the server, and then the returned response replaces the container it was originally requested for. Unfortunately, the request isn't going out for me when I click the back button.

screen shot 2015-04-14 at 5 11 25 pm

In this network log, I make three requests and go back. I go to the favorites page, the members page, back to the favorites page, then I attempt to click the back button to go back to the members page. The request doesn't successfully go out at that point. The last bit of information I can bring to the table is that if I put a breakpoint here, and then click the back button in the same scenario, the event.state attribute is an empty object. The event.originalEvent.state happens to not be an empty object, but I've tried replacing event.state with that to no avail.

At the end of the day, I'm just trying to get the pjax request to fire again on back, like it does in the demo.

jayd3e avatar Apr 14 '15 22:04 jayd3e

There will be no requests when going Back/Forward using browser buttons, gestures, or keyboard shortcuts, because of pjax internal cache. The previous content is restored from cache instead of making a server request.

If the content on your page isn't restored to previous state when you go back, then something is wrong with our content restoration strategy. Most likely the problem is that you're using pjax containers that are nested within each other (#page and #content). Please upgrade to latest jquery-pjax (if you haven't) and put a breakpoint here to see what's going on, thanks

mislav avatar Apr 15 '15 06:04 mislav

Awesome, thanks for the quick reply. Will definitely try that now.

jayd3e avatar Apr 15 '15 15:04 jayd3e

Okay so upgraded to the latest jquery-pjax, and I put a breakpoint where you said. What's happening is occasionally I will click the back button and the state.container will be undefined. Here is a screenshot of this happening:

screen shot 2015-04-15 at 11 41 00 am

From what I can tell, it's happening on every single back button attempt, besides the initial request of the page. So in other words, it appears that the initial request for the page(when pjax starts up) is stored off, but all subsequent attempts to store of the container content don't work.

jayd3e avatar Apr 15 '15 16:04 jayd3e

Do you have any other code on your site that uses history.pushState/replaceState?

mislav avatar Apr 16 '15 13:04 mislav

@mislav yeah I do. I'm using backbone with pushState set to true. I take it that pushState/replaceState must be getting called in a way that jquery-pjax can't handle?

jayd3e avatar Apr 20 '15 17:04 jayd3e

You shouldn't use other pushState stuff with pjax. Or, if you use it, do that at your own risk, but then you can't ask for our support, since the README says this isn't supported yet. There's only 1 history stack and it's extremely confusing to pjax if another different library is managing state as well.

mislav avatar Apr 20 '15 18:04 mislav