diff --git a/mithril.js b/mithril.js index d727537f..568527a0 100644 --- a/mithril.js +++ b/mithril.js @@ -908,8 +908,11 @@ Mithril = m = new function app(window, undefined) { if (maybeXhr != null) xhr = maybeXhr } - if (options.data && (type.call(options.data) != sStr && options.data.constructor != window.FormData)) throw "Request data should be either be a string or FormData. Check the `serialize` option in `m.request`"; - xhr.send(options.method == "GET" || !options.data ? "" : options.data); + var data = options.method == "GET" || !options.data ? "" : options.data + if (data && (type.call(data) != sStr && data.constructor != window.FormData)) { + throw "Request data should be either be a string or FormData. Check the `serialize` option in `m.request`"; + } + xhr.send(data); return xhr } } diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index ecc27d3d..d1c9ca13 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1699,6 +1699,11 @@ function testMithril(mock) { mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop() === "bar" }) + test(function() { + var prop = m.request({method: "GET", url: "test", data: {foo: 1}}) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + return prop().url === "test?foo=1" + }) // m.request over jsonp test(function(){