diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index 8d55ab3e53..8fde2ca91b 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -161,8 +161,18 @@ OpenLayers.Request = { } }; - request.send(config.data); - + // send request (optionally with data) and return + // call in a timeout for asynchronous requests so the return is + // available before readyState == 4 for cached docs + if(config.async === false) { + request.send(config.data); + } else { + window.setTimeout(function(){ + if (request._aborted !== true) { + request.send(config.data); + } + }, 0); + } return request; }, diff --git a/lib/OpenLayers/Request/XMLHttpRequest.js b/lib/OpenLayers/Request/XMLHttpRequest.js index 1d7476ad19..9bf714f3a3 100644 --- a/lib/OpenLayers/Request/XMLHttpRequest.js +++ b/lib/OpenLayers/Request/XMLHttpRequest.js @@ -128,7 +128,7 @@ // fCleanTransport(oRequest); // Uncomment this block if you need a fix for IE cache -/**/ +/* // BUGFIX: IE - cache issue if (!oRequest._object.getResponseHeader("Date")) { // Save object to cache @@ -192,7 +192,7 @@ // Return now - wait until re-sent request is finished return; }; -/**/ +*/ // BUGFIX: IE - memory leak in interrupted if (bIE && bAsync) window.detachEvent("onunload", fOnUnload); diff --git a/tests/Request.html b/tests/Request.html index 336e627840..6fac6eff9b 100644 --- a/tests/Request.html +++ b/tests/Request.html @@ -371,6 +371,22 @@ teardown(); } + function test_abort(t) { + t.plan(0); + var fail = false; + OpenLayers.Request.XMLHttpRequest.onsend = function(args) { + fail = true; + } + t.delay_call(0.5, function() { + if (fail === true) { + t.fail("Send should not be called because request is aborted"); + } + OpenLayers.Request.XMLHttpRequest.onsend = null; + }); + var protocol = new OpenLayers.Protocol.HTTP(); + protocol.abort(protocol.read()); + } +