Changeset 7335
- Timestamp:
- 06/09/08 15:51:38 (2 months ago)
- Files:
-
- trunk/openlayers/build/license.txt (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Ajax.js (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Format/KML.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/GML.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/MapGuide.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Layer/Text.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/WFS.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Request (added)
- trunk/openlayers/lib/OpenLayers/Request.js (added)
- trunk/openlayers/lib/OpenLayers/Request/XMLHttpRequest.js (added)
- trunk/openlayers/lib/OpenLayers/Tile/WFS.js (modified) (4 diffs)
- trunk/openlayers/tests/Ajax.html (modified) (1 diff)
- trunk/openlayers/tests/Request (added)
- trunk/openlayers/tests/Request.html (added)
- trunk/openlayers/tests/Request/XMLHttpRequest.html (added)
- trunk/openlayers/tests/Tile/WFS.html (modified) (2 diffs)
- trunk/openlayers/tests/list-tests.html (modified) (1 diff)
- trunk/openlayers/tests/manual/ajax.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/build/license.txt
r5614 r7335 44 44 **/ 45 45 46 /** 47 * Contains XMLHttpRequest.js <http://code.google.com/p/xmlhttprequest/> 48 * Copyright 2007 Sergey Ilinsky (http://www.ilinsky.com) 49 * 50 * Licensed under the Apache License, Version 2.0 (the "License"); 51 * you may not use this file except in compliance with the License. 52 * You may obtain a copy of the License at 53 * http://www.apache.org/licenses/LICENSE-2.0 54 */ trunk/openlayers/lib/OpenLayers.js
r6818 r7335 85 85 "Rico/Color.js", 86 86 "OpenLayers/Ajax.js", 87 "OpenLayers/Request.js", 88 "OpenLayers/Request/XMLHttpRequest.js", 87 89 "OpenLayers/Events.js", 88 90 "OpenLayers/Projection.js", trunk/openlayers/lib/OpenLayers/Ajax.js
r7039 r7335 31 31 32 32 33 /** 34 * @param {} request 35 */ 33 /** 34 * Function: OpenLayers.nullHandler 35 * @param {} request 36 */ 36 37 OpenLayers.nullHandler = function(request) { 37 38 alert(OpenLayers.i18n("unhandledRequest", {'statusText':request.statusText})); … … 40 41 /** 41 42 * Function: loadURL 42 * Background load a document. 43 * Background load a document. For more flexibility in using XMLHttpRequest, 44 * see the <OpenLayers.Request> methods. 43 45 * 44 46 * Parameters: … … 50 52 * onComplete - {Function} Optional callback for success. The callback 51 53 * will be called with this set to caller and will receive the request 52 * object as an argument. 54 * object as an argument. Note that if you do not specify an onComplete 55 * function, <OpenLayers.nullHandler> will be called (which pops up an 56 * alert dialog). 53 57 * onFailure - {Function} Optional callback for failure. In the event of 54 58 * a failure, the callback will be called with this set to caller and will 55 * receive the request object as an argument. 59 * receive the request object as an argument. Note that if you do not 60 * specify an onComplete function, <OpenLayers.nullHandler> will be called 61 * (which pops up an alert dialog). 56 62 * 57 63 * Returns: 58 * { XMLHttpRequest} The request object. To abort loading, call59 * request.abort().64 * {<OpenLayers.Request.XMLHttpRequest>} The request object. To abort loading, 65 * call request.abort(). 60 66 */ 61 67 OpenLayers.loadURL = function(uri, params, caller, 62 68 onComplete, onFailure) { 63 64 var success = (onComplete) ? OpenLayers.Function.bind(onComplete, caller) 65 : OpenLayers.nullHandler; 66 67 var failure = (onFailure) ? OpenLayers.Function.bind(onFailure, caller) 68 : OpenLayers.nullHandler; 69 70 // from prototype.js 71 var request = new OpenLayers.Ajax.Request( 72 uri, 73 { 74 method: 'get', 75 parameters: params, 76 onComplete: success, 77 onFailure: failure 78 } 79 ); 80 return request.transport; 69 70 if(typeof params == 'string') { 71 params = OpenLayers.Util.getParameters(params); 72 } 73 var success = (onComplete) ? onComplete : OpenLayers.nullHandler; 74 var failure = (onFailure) ? onFailure : OpenLayers.nullHandler; 75 76 return OpenLayers.Request.GET({ 77 url: uri, params: params, 78 success: success, failure: failure, scope: caller 79 }); 81 80 }; 82 81 … … 264 263 /** 265 264 * Class: OpenLayers.Ajax.Request 265 * *Deprecated*. Use <OpenLayers.Request> method instead. 266 266 * 267 267 * Inherit: trunk/openlayers/lib/OpenLayers/Format/KML.js
r7311 r7335 250 250 */ 251 251 fetchLink: function(href) { 252 var request = new OpenLayers.Ajax.Request(href, 253 {method: 'get', asynchronous: false }); 254 255 if (request && request.transport) { 256 return request.transport.responseText; 252 var request = OpenLayers.Request.GET({url: href, async: false}); 253 if (request) { 254 return request.responseText; 257 255 } 258 256 }, trunk/openlayers/lib/OpenLayers/Layer/GML.js
r6573 r7335 101 101 loadGML: function() { 102 102 if (!this.loaded) { 103 var results = OpenLayers.loadURL(this.url, null, this, this.requestSuccess, this.requestFailure); 103 OpenLayers.Request.GET({ 104 url: this.url, 105 success: this.requestSuccess, 106 failure: this.requestFailure, 107 scope: this 108 }); 104 109 this.loaded = true; 105 110 } trunk/openlayers/lib/OpenLayers/Layer/GeoRSS.js
r7015 r7335 101 101 if (!this.loaded) { 102 102 this.events.triggerEvent("loadstart"); 103 OpenLayers.loadURL(this.location, null, this, this.parseData); 103 OpenLayers.Request.GET({ 104 url: this.location, 105 success: this.parseData, 106 scope: this 107 }); 104 108 this.loaded = true; 105 109 } … … 128 132 * 129 133 * Parameters: 130 * ajaxRequest - { XMLHttpRequest}134 * ajaxRequest - {<OpenLayers.Request.XMLHttpRequest>} 131 135 */ 132 136 parseData: function(ajaxRequest) { trunk/openlayers/lib/OpenLayers/Layer/MapGuide.js
r6748 r7335 203 203 getVisParams.format = 'text/xml'; 204 204 getVisParams = OpenLayers.Util.extend(getVisParams, params); 205 206 new OpenLayers.Ajax.Request(this.url, 207 { parameters: getVisParams, 208 method: 'get', 209 asynchronous: false //must be synchronous call to return control here 210 }); 205 206 OpenLayers.Request.GET({ 207 url: this.url, params: getVisParams, async: false 208 }); 211 209 } 212 210 trunk/openlayers/lib/OpenLayers/Layer/Text.js
r7334 r7335 110 110 111 111 this.events.triggerEvent("loadstart"); 112 OpenLayers.loadURL(this.location, null, 113 this, this.parseData, onFail); 112 OpenLayers.Request.GET({ 113 url: this.location, 114 success: this.parseData, 115 failure: onFail, 116 scope: this 117 }); 114 118 this.loaded = true; 115 119 } … … 138 142 * 139 143 * Parameters: 140 * ajaxRequest - { XMLHttpRequest}144 * ajaxRequest - {<OpenLayers.Request.XMLHttpRequest>} 141 145 */ 142 146 parseData: function(ajaxRequest) { trunk/openlayers/lib/OpenLayers/Layer/WFS.js
r7311 r7335 456 456 457 457 var data = this.writer.write(this.features); 458 459 var url = this.url; 460 461 var success = OpenLayers.Function.bind(this.commitSuccess, this); 462 463 var failure = OpenLayers.Function.bind(this.commitFailure, this); 464 465 // from prototype.js 466 new OpenLayers.Ajax.Request(url, 467 { method: 'post', 468 postBody: data, 469 onComplete: success, 470 onFailure: failure 471 } 472 ); 458 459 OpenLayers.Request.POST({ 460 url: this.url, 461 data: data, 462 success: this.commitSuccess, 463 failure: this.commitFailure, 464 scope: this 465 }); 473 466 }, 474 467 trunk/openlayers/lib/OpenLayers/Tile/WFS.js
r6573 r7335 33 33 /** 34 34 * Property: request 35 * { OpenLayers.Ajax.Request}35 * {<OpenLayers.Request.XMLHttpRequest>} 36 36 */ 37 37 request: null, … … 101 101 /** 102 102 * Method: loadFeaturesForRegion 103 * get the full request string from the ds and the tile params 104 * and call the AJAX loadURL(). 103 * Abort any pending requests and issue another request for data. 105 104 * 106 105 * Input are function pointers for what to do on success and failure. … … 114 113 this.request.abort(); 115 114 } 116 this.request = OpenLayers.loadURL(this.url, null, this, success); 115 this.request = OpenLayers.Request.GET({ 116 url: this.url, 117 success: success, 118 failure: failure, 119 scope: this 120 }); 117 121 }, 118 122 … … 123 127 * 124 128 * Parameters: 125 * request - { XMLHttpRequest}129 * request - {<OpenLayers.Request.XMLHttpRequest>} 126 130 */ 127 131 requestSuccess:function(request) { trunk/openlayers/tests/Ajax.html
r6719 r7335 5 5 6 6 function test_Ajax_loadUrl(t) { 7 t.plan(1); 8 var req = OpenLayers.Ajax.Request; 9 OpenLayers.ProxyHost = "/?url="; 10 OpenLayers.Ajax.Request.prototype.request = function(uri) { 11 t.eq(uri, "/?url=http%3A%2F%2Fexample.com%2F%3Fformat%3Dimage%2Bkml", "URI matches what we expect from loadurl"); 12 } 13 OpenLayers.loadURL("http://example.com/?format=image+kml"); 7 t.plan(5); 8 var _get = OpenLayers.Request.GET; 9 var caller = {}; 10 var onComplete = function() {}; 11 var onFailure = function() {}; 12 var params = {}; 13 OpenLayers.Request.GET = function(config) { 14 t.eq(config.url, "http://example.com/?format=image+kml", "correct url") 15 t.eq(config.params, params, "correct params"); 16 t.eq(config.scope, caller, "correct scope"); 17 t.ok(config.success === onComplete, "correct success callback"); 18 t.ok(config.failure === onFailure, "correct failure callback"); 19 }; 20 OpenLayers.loadURL("http://example.com/?format=image+kml", params, caller, onComplete, onFailure); 21 OpenLayers.Request.GET = _get; 14 22 } 15 23 </script> trunk/openlayers/tests/Tile/WFS.html
r6724 r7335 65 65 var g_Success = {}; 66 66 67 var tLoadURL = OpenLayers.loadURL;68 OpenLayers. loadURL = function(url, params, caller, onComplete) {69 t.ok( url == tile.url, "tile's url correctly passed as 1st param to loadURL");70 t.ok( params == null, "null passed as 2nd param to loadURL");71 t.ok(c aller == tile, "tile passed as 3rd param to loadURL");72 t.ok( onComplete == g_Success, "success param from loadFeaturesForRegion() passed as 4th param to loadURL");67 var _get = OpenLayers.Request.GET; 68 OpenLayers.Request.GET = function(config) { 69 t.ok(config.url == tile.url, "tile's url correctly passed"); 70 t.ok(config.params == null, "null params"); 71 t.ok(config.scope == tile, "tile passed as scope"); 72 t.ok(config.success == g_Success, "success passed"); 73 73 }; 74 74 … … 83 83 }; 84 84 OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]); 85 86 OpenLayers. loadURL = tLoadURL;85 86 OpenLayers.Request.GET = _get; 87 87 } 88 88 trunk/openlayers/tests/list-tests.html
r6832 r7335 58 58 <li>Layer.html</li> 59 59 <li>Renderer.html</li> 60 <li>Request.html</li> 61 <li>Request/XMLHttpRequest.html</li> 60 62 <li>Layer/EventPane.html</li> 61 63 <li>Layer/FixedZoomLevels.html</li> trunk/openlayers/tests/manual/ajax.html
r6408 r7335 1 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 2 <head> 3 <title>Ajax Acceptance Test</title> 4 <style type="text/css"> 5 6 body { 7 font-size: 0.8em; 8 } 9 p { 10 padding-top: 1em; 11 } 12 13 .buttons { 14 margin: 1em; 15 float: left; 16 } 17 18 </style> 19 3 <title>XHR Acceptance Test</title> 20 4 <script src="../../lib/OpenLayers.js"></script> 21 5 <script type="text/javascript"> 22 6 var url = "ajax.txt"; 23 7 function sendSynchronous(){ 24 var request = new OpenLayers.Ajax.Request(url, { 25 'asynchronous': false, 26 onComplete: function() { 8 var request = OpenLayers.Request.GET({ 9 url: url, 10 async: false, 11 callback: function() { 27 12 document.getElementById('send_sync').value += 'request completed\n'; 28 13 } … … 31 16 } 32 17 function sendAsynchronous(){ 33 var request = new OpenLayers.Ajax.Request(url, { 34 onComplete: function() { 18 var request = OpenLayers.Request.GET({ 19 url: url, 20 callback: function() { 35 21 document.getElementById('send_sync').value += 'request completed\n'; 36 22 } … … 39 25 } 40 26 function sendAndAbort(){ 41 var request = new OpenLayers.Ajax.Request(url, { 42 onComplete: function(request) { 43 if (request.responseText == '') { 44 document.getElementById('send_sync').value += 'request aborted\n'; 45 } 27 var request = OpenLayers.Request.GET({ 28 url: url, 29 callback: function() { 30 document.getElementById('send_sync').value += 'never called\n'; 46 31 } 47 32 }); 48 request. transport.abort();33 request.abort(); 49 34 document.getElementById('send_sync').value += 'other processing\n'; 50 35 } 51 36 52 </script> 53 </head> 54 <body > 55 <div class="buttons"> 56 <button onclick="sendSynchronous()">Send an synchronous Ajax request</button><br /> 57 <button onclick="sendAsynchronous()">Send an asynchronous Ajax request</button><br /> 58 <button onclick="sendAndAbort()">Send a request and abort it</button><br /> 37 </script> 38 </head> 39 <body > 40 <button onclick="sendSynchronous()">synchronous</button> 41 expected output: "request completed" then "other processing"<br /> 42 <button onclick="sendAsynchronous()">asynchronous</button> 43 expected output: "other processing" then "request completed"<br /> 44 <button onclick="sendAndAbort()">send and abort</button> 45 expected output: "other processing" (and not "never called")<br /> 59 46 <textarea id="send_sync" rows="6"></textarea><br /> 60 47 <button onclick="document.getElementById('send_sync').value = ''">Clear</button> 61 </div>62 <p><b></b></p>63 <p>Clicking on the different buttons should give the following results in the textarea below :</p>64 <ul>65 <li>synchronous: "request completed" then "other processing"</li>66 <li>asynchronous: "other processing" then "request completed"</li>67 <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>68 </ul>69 48 </body> 70 49 </html>
