Skip to content

Commit 71cd225

Browse files
committed
Merge branch 'data-array'
Closes #270
2 parents 4d3e868 + 8b442cb commit 71cd225

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

jquery.pjax.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ function pjax(options) {
191191
// Without adding this secret parameter, some browsers will often
192192
// confuse the two.
193193
if (!options.data) options.data = {}
194-
options.data._pjax = context.selector
194+
if ($.isArray(options.data)) {
195+
options.data.push({name: '_pjax', value: context.selector})
196+
} else {
197+
options.data._pjax = context.selector
198+
}
195199

196200
function fire(type, args, props) {
197201
if (!props) props = {}

test/unit/pjax.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ if ($.support.pjax) {
215215
})
216216
})
217217

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

221221
frame.$('#main').on('pjax:success', function() {
@@ -225,6 +225,43 @@ if ($.support.pjax) {
225225
})
226226
frame.$.pjax({
227227
url: "env.html",
228+
data: undefined,
229+
container: "#main"
230+
})
231+
})
232+
233+
asyncTest("sets hidden _pjax param if array data is supplied", 1, function() {
234+
var frame = this.frame
235+
236+
frame.$('#main').on('pjax:success', function() {
237+
var env = JSON.parse(frame.$("#env").text())
238+
deepEqual(env['rack.request.query_hash'], {
239+
_pjax: '#main',
240+
foo: 'bar'
241+
})
242+
start()
243+
})
244+
frame.$.pjax({
245+
url: "env.html",
246+
data: [{ name: "foo", value: "bar" }],
247+
container: "#main"
248+
})
249+
})
250+
251+
asyncTest("sets hidden _pjax param if object data is supplied", 1, function() {
252+
var frame = this.frame
253+
254+
frame.$('#main').on('pjax:success', function() {
255+
var env = JSON.parse(frame.$("#env").text())
256+
deepEqual(env['rack.request.query_hash'], {
257+
_pjax: '#main',
258+
foo: 'bar'
259+
})
260+
start()
261+
})
262+
frame.$.pjax({
263+
url: "env.html",
264+
data: { foo: "bar" },
228265
container: "#main"
229266
})
230267
})

0 commit comments

Comments
 (0)