Simpler workaround for local d3.xhr.
If the error flag is set, the response attribute [1] should be the empty string or null. So even if a request fails and the response has been partially loaded, this logic should still work. This check will fail for local requests where the response entity body is the empty string, but I don't think it's possible to detect this situation in current browser implementations. jQuery has the same issue, for example. [1]: http://www.w3.org/TR/XMLHttpRequest/#the-response-attribute
This commit is contained in:
Родитель
95b1eaaf68
Коммит
53d117e6d3
|
@ -494,28 +494,11 @@ d3.xhr = function(url, mime, callback) {
|
|||
req.onreadystatechange = function() {
|
||||
if (req.readyState === 4) {
|
||||
var s = req.status;
|
||||
if (!s && d3_xhrLocal && !d3_xhrCrossDomain(url)) {
|
||||
s = req.responseText ? 200 : 404;
|
||||
}
|
||||
callback(s >= 200 && s < 300 || s === 304 ? req : null);
|
||||
callback(!s && req.response || s >= 200 && s < 300 || s === 304 ? req : null);
|
||||
}
|
||||
};
|
||||
req.send(null);
|
||||
};
|
||||
|
||||
var d3_xhrUrl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
|
||||
d3_xhrLocation,
|
||||
d3_xhrLocal = false;
|
||||
try {
|
||||
d3_xhrLocation = d3_xhrUrl.exec(document.location.href);
|
||||
d3_xhrLocal = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/i.test(d3_xhrLocation[1]);
|
||||
} catch(e) {}
|
||||
|
||||
function d3_xhrCrossDomain(url) {
|
||||
var parts = d3_xhrUrl.exec(url);
|
||||
return !!(parts && (parts[1] != d3_xhrLocation[1] || parts[2] != d3_xhrLocation[2] ||
|
||||
(parts[3] || (parts[1] === "http:" ? 80 : 443)) != (d3_xhrLocation[3] || (ajaxLocParts[1] === "http:" ? 80 : 443))));
|
||||
}
|
||||
d3.text = function(url, mime, callback) {
|
||||
function ready(req) {
|
||||
callback(req && req.responseText);
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -7,25 +7,8 @@ d3.xhr = function(url, mime, callback) {
|
|||
req.onreadystatechange = function() {
|
||||
if (req.readyState === 4) {
|
||||
var s = req.status;
|
||||
if (!s && d3_xhrLocal && !d3_xhrCrossDomain(url)) {
|
||||
s = req.responseText ? 200 : 404;
|
||||
}
|
||||
callback(s >= 200 && s < 300 || s === 304 ? req : null);
|
||||
callback(!s && req.response || s >= 200 && s < 300 || s === 304 ? req : null);
|
||||
}
|
||||
};
|
||||
req.send(null);
|
||||
};
|
||||
|
||||
var d3_xhrUrl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
|
||||
d3_xhrLocation,
|
||||
d3_xhrLocal = false;
|
||||
try {
|
||||
d3_xhrLocation = d3_xhrUrl.exec(document.location.href);
|
||||
d3_xhrLocal = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/i.test(d3_xhrLocation[1]);
|
||||
} catch(e) {}
|
||||
|
||||
function d3_xhrCrossDomain(url) {
|
||||
var parts = d3_xhrUrl.exec(url);
|
||||
return !!(parts && (parts[1] != d3_xhrLocation[1] || parts[2] != d3_xhrLocation[2] ||
|
||||
(parts[3] || (parts[1] === "http:" ? 80 : 443)) != (d3_xhrLocation[3] || (ajaxLocParts[1] === "http:" ? 80 : 443))));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче