diff --git a/mithril.js b/mithril.js index 91348bb4..9f82faa7 100644 --- a/mithril.js +++ b/mithril.js @@ -949,6 +949,7 @@ Mithril = m = new function app(window, undefined) { if (xhrOptions.background !== true) m.endComputation() } ajax(xhrOptions) + deferred.promise(xhrOptions.initialValue) return deferred.promise } diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 56c73b52..ecc27d3d 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1687,6 +1687,18 @@ function testMithril(mock) { xhr.onreadystatechange() return xhr.$headers["Content-Type"] === undefined }) + test(function() { + var prop = m.request({method: "POST", url: "test", initialValue: "foo"}) + var initialValue = prop(); + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + + return initialValue === "foo" + }) + test(function() { + var prop = m.request({method: "POST", url: "test", initialValue: "foo"}).then(function(value) {return "bar"}) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + return prop() === "bar" + }) // m.request over jsonp test(function(){