The loadURL function now returns something that acts more like XMLHttpRequest should. If you name this return request, call request.abort to abort the request. r=crschmidt (closes #1386)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@6408 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -53,8 +53,8 @@ OpenLayers.nullHandler = function(request) {
|
|||||||
* receive the request object as an argument.
|
* receive the request object as an argument.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {OpenLayers.Ajax.Request} The request object. To abort loading, call
|
* {XMLHttpRequest} The request object. To abort loading, call
|
||||||
* request.transport.abort();
|
* request.abort().
|
||||||
*/
|
*/
|
||||||
OpenLayers.loadURL = function(uri, params, caller,
|
OpenLayers.loadURL = function(uri, params, caller,
|
||||||
onComplete, onFailure) {
|
onComplete, onFailure) {
|
||||||
@@ -66,7 +66,7 @@ OpenLayers.loadURL = function(uri, params, caller,
|
|||||||
: OpenLayers.nullHandler;
|
: OpenLayers.nullHandler;
|
||||||
|
|
||||||
// from prototype.js
|
// from prototype.js
|
||||||
return new OpenLayers.Ajax.Request(
|
var request = new OpenLayers.Ajax.Request(
|
||||||
uri,
|
uri,
|
||||||
{
|
{
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@@ -75,6 +75,7 @@ OpenLayers.loadURL = function(uri, params, caller,
|
|||||||
onFailure: failure
|
onFailure: failure
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
return request.transport;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
|
|||||||
this.features = null;
|
this.features = null;
|
||||||
this.url = null;
|
this.url = null;
|
||||||
if(this.request) {
|
if(this.request) {
|
||||||
this.request.transport.abort();
|
this.request.abort();
|
||||||
//this.request.destroy();
|
//this.request.destroy();
|
||||||
this.request = null;
|
this.request = null;
|
||||||
}
|
}
|
||||||
@@ -111,8 +111,7 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
|
|||||||
*/
|
*/
|
||||||
loadFeaturesForRegion:function(success, failure) {
|
loadFeaturesForRegion:function(success, failure) {
|
||||||
if(this.request) {
|
if(this.request) {
|
||||||
this.request.transport.abort();
|
this.request.abort();
|
||||||
//this.request.destroy();
|
|
||||||
}
|
}
|
||||||
this.request = OpenLayers.loadURL(this.url, null, this, success);
|
this.request = OpenLayers.loadURL(this.url, null, this, success);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -72,10 +72,8 @@
|
|||||||
|
|
||||||
//running request (cancelled) -- 4 tests + 1 test (for request abort)
|
//running request (cancelled) -- 4 tests + 1 test (for request abort)
|
||||||
tile.request = {
|
tile.request = {
|
||||||
transport: {
|
'abort': function() {
|
||||||
'abort': function() {
|
t.ok(true, "request aborted");
|
||||||
t.ok(true, "request aborted");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
|
OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
|
||||||
@@ -100,10 +98,8 @@
|
|||||||
|
|
||||||
var _gAbort = false;
|
var _gAbort = false;
|
||||||
tile.request = {
|
tile.request = {
|
||||||
transport: {
|
abort: function() {
|
||||||
abort: function() {
|
_gAbort = true;
|
||||||
_gAbort = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
<head>
|
<head>
|
||||||
<title>Draw Feature Acceptance Test</title>
|
<title>Ajax Acceptance Test</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>synchronous: "request completed" then "other processing"</li>
|
<li>synchronous: "request completed" then "other processing"</li>
|
||||||
<li>asynchronous: "other processing" then "request completed"</li>
|
<li>asynchronous: "other processing" then "request completed"</li>
|
||||||
<li>abort: "request aborted" then "other processing"</li>
|
<li>abort: "request aborted" then "other processing" (note that real XHR behavior would not call onComplete with abort - meaning "request aborted" would not be displayed here)</li>
|
||||||
</ul>
|
</ul>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user