Improve XHR and ol.net.jsonp result/failure handling
This commit is contained in:
@@ -75,7 +75,7 @@ ol.featureloader.loadFeaturesXhr = function(url, format, success, failure) {
|
||||
* @private
|
||||
*/
|
||||
xhr.onload = function(event) {
|
||||
if (xhr.status < 400) {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
var type = format.getType();
|
||||
/** @type {Document|Node|Object|string|undefined} */
|
||||
var source;
|
||||
|
||||
@@ -14,19 +14,23 @@ goog.provide('ol.net');
|
||||
*/
|
||||
ol.net.jsonp = function(url, callback, opt_errback, opt_callbackParam) {
|
||||
var script = goog.global.document.createElement('script');
|
||||
script.async = true;
|
||||
var key = 'olc_' + goog.getUid(callback);
|
||||
function cleanup() {
|
||||
delete goog.global[key];
|
||||
script.parentNode.removeChild(script);
|
||||
}
|
||||
script.async = true;
|
||||
script.src = url + (url.indexOf('?') == -1 ? '?' : '&') +
|
||||
(opt_callbackParam || 'callback') + '=' + key;
|
||||
var timer = goog.global.setTimeout(function() {
|
||||
delete goog.global[key];
|
||||
cleanup();
|
||||
if (opt_errback) {
|
||||
opt_errback();
|
||||
}
|
||||
}, 10000);
|
||||
goog.global[key] = function(data) {
|
||||
goog.global.clearTimeout(timer);
|
||||
delete goog.global[key];
|
||||
cleanup();
|
||||
callback(data);
|
||||
};
|
||||
goog.global.document.getElementsByTagName('head')[0].appendChild(script);
|
||||
|
||||
@@ -46,7 +46,7 @@ ol.source.TileJSON = function(options) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', options.url, true);
|
||||
xhr.onload = function(e) {
|
||||
if (xhr.status < 400) {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
var response = /** @type {TileJSON} */(JSON.parse(xhr.responseText));
|
||||
this.handleTileJSONResponse(response);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user