diff --git a/mithril.js b/mithril.js index 24e73726..d9ca2383 100644 --- a/mithril.js +++ b/mithril.js @@ -872,7 +872,7 @@ Mithril = m = new function app(window, undefined) { } function bindData(xhrOptions, data, serialize) { if (data && Object.keys(data).length > 0) { - if (xhrOptions.method == "GET") { + if (xhrOptions.method == "GET" && xhrOptions.dataType != "jsonp") { xhrOptions.url = xhrOptions.url + (xhrOptions.url.indexOf("?") < 0 ? "?" : "&") + buildQueryString(data) } else xhrOptions.data = serialize(data) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index c35428c1..04aece02 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1761,6 +1761,39 @@ function testMithril(mock) { mock.document.removeChild(body); return correctData; }) + test(function(){ + var body = mock.document.createElement("body"); + mock.document.body = body; + mock.document.appendChild(body); + + var _window = mock; + var error = m.prop(false); + var req = m.request({ + url: "/test", + dataType: "jsonp", + method: "GET", + data: { foo: "bar" }, + background: true + }); + var callbackKeys = []; + Object.keys(_window).forEach(function(globalKey){ + if(globalKey.indexOf("mithril_callback") > -1) + callbackKeys.push(globalKey); + }); + var scriptTag = null; + mock.document.getElementsByTagName("script").forEach(function(script){ + if(!scriptTag && script.src.indexOf(callbackKeys[0]) > -1) + scriptTag = script; + }); + var correctData = false; + if(scriptTag){ + correctData = scriptTag.src.match(/foo=bar/g).length == 1; + mock.document.body.removeChild(scriptTag); + delete _window[callbackKeys[0]]; + } + mock.document.removeChild(body); + return correctData; + }) //m.deferred test(function() {