prevent stupid error on GET w/ data

This commit is contained in:
Leo Horie 2014-11-13 20:05:44 -05:00
parent 35f4d87f67
commit 5501d23652
2 changed files with 10 additions and 2 deletions

View file

@ -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
}
}

View file

@ -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(){