Skip to content

Preserve data on get without dependency on server header #146

Merged
merged 5 commits into from May 21, 2012

4 participants

@anttimattila

When server doesn't return url in X-PJAX-URL header many tests fail. Mainly due to data parameters not being added to url on GET requests.

This fixes all but redirection and reduces dependency on the response header.

@josh josh commented on an outdated diff May 21, 2012
jquery.pjax.js
@@ -165,6 +165,13 @@ var pjax = $.pjax = function( options ) {
if (!fire('pjax:beforeSend', [xhr, settings]))
return false
+
+ function qualifyURL(url) {
+ var a = document.createElement('a')
+ a.href = url
+ return a.href
+ }
+ options.requestUrl = qualifyURL(settings.url)
@josh
Collaborator
josh added a note May 21, 2012

Theres a parseURL helper already. parseURL(settings.url).href should work.

I think we should avoid setting requestUrl on options, maybe just make a new local for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@josh
Collaborator
josh commented May 21, 2012

Otherwise, I dig it.

@travisbot

This pull request passes (merged ed34151 into 73dd1ab).

@travisbot

This pull request passes (merged 1185f50 into 73dd1ab).

@josh josh and 1 other commented on an outdated diff May 21, 2012
jquery.pjax.js
@@ -165,6 +165,8 @@ var pjax = $.pjax = function( options ) {
if (!fire('pjax:beforeSend', [xhr, settings]))
return false
+
+ pjax.requestUrl = parseURL(settings.url).href
@josh
Collaborator
josh added a note May 21, 2012

Maybe just a local? var requestUrl inside the pjax function scope.

@anttimattila
anttimattila added a note May 21, 2012

Isn't it used outside the pjax function scope:

function extractContainer(data, xhr, options) {
var obj = {}

// Prefer X-PJAX-URL header if it was set, otherwise fallback to
// using the original requested url.
obj.url = stripPjaxParam(xhr.getResponseHeader('X-PJAX-URL') || pjax.requestUrl)
...

@josh
Collaborator
josh added a note May 21, 2012

Ah, sorry its hard to tell from the diff. I guess the original way assigning it to options make sense then. Sorry for the confusion.

@anttimattila
anttimattila added a note May 21, 2012

No problem. I changed it back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@anttimattila

Not sure what you mean by local. I moved the requestUrl property from options to pjax, is that what you ment?
I made the changes and pushed them to the branch, apparently they also update this pull request.

@josh
Collaborator
josh commented May 21, 2012

Just a local variable: var requestUrl.

Yeah, just keep pushing to the same branch. No need for another pull.

@travisbot

This pull request passes (merged 65f8c7c into 73dd1ab).

@josh josh merged commit e0d306d into defunkt:master May 21, 2012
@stephanfowler

This commit seems to have caused an change in behaviour. Previously, this:
$.pjax({
url: 'http://example.com'.
data: { foo: 'bar' },
etc..
});

...would cause a pushState of this url:
http://example.com

...whereas after this commit, it causes a pushState of the url:
http://example.com?foo=bar

Any idea how force the former behaviour?

I haven't looked into this yet to see what's going on, but if this commit broke something, I'd just revert it.

Yep, did that. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.