I’m trying to get a custom response handler working and am running in to what I think may be a bug. It may well be that I'm doing something wrong though!
As a reduced test case, I've tested this out with the handleResponse example from the read me, as below:
var pjax = new Pjax();
pjax._handleResponse = pjax.handleResponse;
pjax.handleResponse = function(responseText, request, href) {
if (request.responseText.match("<html")) {
pjax._handleResponse(responseText, request, href);
} else {
// handle response here
}
}
The behaviour is great, as expected, when you click around the links on the site. It is also fine for the first "back" click (popstate event) in the browser. Subsequent popstate events, however, return the same responseText, request, and href every time, as if it’s stuck on the same page.
Is there something I'm missing, maybe something that I should be resetting after a successful pjax event? Any help you could provide would be really, really appreciated!
I’m trying to get a custom response handler working and am running in to what I think may be a bug. It may well be that I'm doing something wrong though!
As a reduced test case, I've tested this out with the `handleResponse` example from the read me, as below:
```
var pjax = new Pjax();
pjax._handleResponse = pjax.handleResponse;
pjax.handleResponse = function(responseText, request, href) {
if (request.responseText.match("<html")) {
pjax._handleResponse(responseText, request, href);
} else {
// handle response here
}
}
```
The behaviour is great, as expected, when you click around the links on the site. It is also fine for the first "back" click (`popstate` event) in the browser. Subsequent `popstate` events, however, return the same `responseText`, `request`, and `href` every time, as if it’s stuck on the same page.
Is there something I'm missing, maybe something that I should be resetting after a successful `pjax` event? Any help you could provide would be really, really appreciated!
I don’t have a website I can demonstrate it on just yet unfortunately and can’t figure out how to do this via Codepen since it involves history... I actually just figured out that I was drastically overcomplicating things by trying to create a custom response handler so am no longer using this method.
Regardless, once I get this online I’ll try to do a demo of the behaviour above in case it is useful but for now, might be best to close it since I’m not sure how I can usefully demonstrate it to you. Very sorry for the faff!
I don’t have a website I can demonstrate it on just yet unfortunately and can’t figure out how to do this via Codepen since it involves history... I actually just figured out that I was drastically overcomplicating things by trying to create a custom response handler so am no longer using this method.
Regardless, once I get this online I’ll try to do a demo of the behaviour above in case it is useful but for now, might be best to close it since I’m not sure how I can usefully demonstrate it to you. Very sorry for the faff!
This bug is being caused by a mistake in the README, and as a result, the code snippet in the first post. The handleResponse function needs to be passed an options parameter, otherwise it has no way to know if it came from a popstate event, and it will end up pushing the current state again.
This bug is being caused by a mistake in the README, and as a result, the code snippet in the first post. The `handleResponse` function needs to be passed an `options` parameter, otherwise it has no way to know if it came from a `popstate` event, and it will end up pushing the current state again.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
I’m trying to get a custom response handler working and am running in to what I think may be a bug. It may well be that I'm doing something wrong though!
As a reduced test case, I've tested this out with the
handleResponseexample from the read me, as below:The behaviour is great, as expected, when you click around the links on the site. It is also fine for the first "back" click (
popstateevent) in the browser. Subsequentpopstateevents, however, return the sameresponseText,request, andhrefevery time, as if it’s stuck on the same page.Is there something I'm missing, maybe something that I should be resetting after a successful
pjaxevent? Any help you could provide would be really, really appreciated!Can you post a link to website or codepen demonstrating the issue?
I don’t have a website I can demonstrate it on just yet unfortunately and can’t figure out how to do this via Codepen since it involves history... I actually just figured out that I was drastically overcomplicating things by trying to create a custom response handler so am no longer using this method.
Regardless, once I get this online I’ll try to do a demo of the behaviour above in case it is useful but for now, might be best to close it since I’m not sure how I can usefully demonstrate it to you. Very sorry for the faff!
Leave it open. I'll try to test it at some point.
This bug is being caused by a mistake in the README, and as a result, the code snippet in the first post. The
handleResponsefunction needs to be passed anoptionsparameter, otherwise it has no way to know if it came from apopstateevent, and it will end up pushing the current state again.