Skip to content

Commit fe20697

Browse files
committed
Cope with array form data in fallback
1 parent 7ce953c commit fe20697

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

jquery.pjax.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ function fallbackPjax(options) {
521521
var pair = value.split('=')
522522
form.append($('<input>', {type: 'hidden', name: pair[0], value: pair[1]}))
523523
})
524+
} else if ($.isArray(data)) {
525+
$.each(data, function(index, value) {
526+
form.append($('<input>', {type: 'hidden', name: value.name, value: value.value}))
527+
})
524528
} else if (typeof data === 'object') {
525529
for (key in data)
526530
form.append($('<input>', {type: 'hidden', name: key, value: data[key]}))

test/unit/pjax_fallback.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,50 @@ asyncTest("POST with data object"+s, function() {
313313
})
314314
})
315315

316+
asyncTest("GET with data array"+s, function() {
317+
var frame = this.frame
318+
319+
this.loaded = function() {
320+
equal(frame.location.pathname, "/env.html")
321+
equal(frame.location.search, "?foo=bar")
322+
323+
var env = JSON.parse(frame.$("#env").text())
324+
equal(env['REQUEST_METHOD'], "GET")
325+
equal(env['rack.request.query_hash']['foo'], 'bar')
326+
327+
start()
328+
}
329+
330+
frame.$.pjax({
331+
type: 'GET',
332+
url: "env.html",
333+
data: [{name: "foo", value: "bar"}],
334+
container: "#main"
335+
})
336+
})
337+
338+
asyncTest("POST with data array"+s, function() {
339+
var frame = this.frame
340+
341+
this.loaded = function() {
342+
equal(frame.location.pathname, "/env.html")
343+
equal(frame.location.search, "")
344+
345+
var env = JSON.parse(frame.$("#env").text())
346+
equal(env['REQUEST_METHOD'], "POST")
347+
equal(env['rack.request.form_hash']['foo'], 'bar')
348+
349+
start()
350+
}
351+
352+
frame.$.pjax({
353+
type: 'POST',
354+
url: "env.html",
355+
data: [{name: "foo", value: "bar"}],
356+
container: "#main"
357+
})
358+
})
359+
316360
asyncTest("GET with data string"+s, function() {
317361
var frame = this.frame
318362

0 commit comments

Comments
 (0)