Skip to content

Commit

Permalink
Merge branch 'data-array'
Browse files Browse the repository at this point in the history
Closes #270
  • Loading branch information
mislav committed Nov 21, 2014
2 parents 4d3e868 + 8b442cb commit 71cd225
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
6 changes: 5 additions & 1 deletion jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ function pjax(options) {
// Without adding this secret parameter, some browsers will often
// confuse the two.
if (!options.data) options.data = {}
options.data._pjax = context.selector
if ($.isArray(options.data)) {
options.data.push({name: '_pjax', value: context.selector})
} else {
options.data._pjax = context.selector
}

function fire(type, args, props) {
if (!props) props = {}
Expand Down
39 changes: 38 additions & 1 deletion test/unit/pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ if ($.support.pjax) {
})
})

asyncTest("sets hidden _pjax param on XHR GET request", function() {
asyncTest("sets hidden _pjax param on XHR GET request", 1, function() {
var frame = this.frame

frame.$('#main').on('pjax:success', function() {
Expand All @@ -225,6 +225,43 @@ if ($.support.pjax) {
})
frame.$.pjax({
url: "env.html",
data: undefined,
container: "#main"
})
})

asyncTest("sets hidden _pjax param if array data is supplied", 1, function() {
var frame = this.frame

frame.$('#main').on('pjax:success', function() {
var env = JSON.parse(frame.$("#env").text())
deepEqual(env['rack.request.query_hash'], {
_pjax: '#main',
foo: 'bar'
})
start()
})
frame.$.pjax({
url: "env.html",
data: [{ name: "foo", value: "bar" }],
container: "#main"
})
})

asyncTest("sets hidden _pjax param if object data is supplied", 1, function() {
var frame = this.frame

frame.$('#main').on('pjax:success', function() {
var env = JSON.parse(frame.$("#env").text())
deepEqual(env['rack.request.query_hash'], {
_pjax: '#main',
foo: 'bar'
})
start()
})
frame.$.pjax({
url: "env.html",
data: { foo: "bar" },
container: "#main"
})
})
Expand Down

0 comments on commit 71cd225

Please sign in to comment.