diff --git a/jquery.pjax.js b/jquery.pjax.js index 4e2bd0ee..b1648382 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -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 = {} diff --git a/test/unit/pjax.js b/test/unit/pjax.js index 9767290a..a1992918 100644 --- a/test/unit/pjax.js +++ b/test/unit/pjax.js @@ -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() { @@ -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" }) })