Merge pull request #1909 from benbro/master

Prevent the error callback from being called twice when getPdf fails because of a cross domain request.
This commit is contained in:
Brendan Dahl 2012-07-20 15:46:39 -07:00
commit 377a96dda7

View File

@ -52,8 +52,16 @@ function getPdf(arg, callback) {
if ('progress' in params) if ('progress' in params)
xhr.onprogress = params.progress || undefined; xhr.onprogress = params.progress || undefined;
if ('error' in params) var calledErrorBack = false;
xhr.onerror = params.error || undefined;
if ('error' in params) {
xhr.onerror = function errorBack() {
if (!calledErrorBack) {
calledErrorBack = true;
params.error();
}
}
}
xhr.onreadystatechange = function getPdfOnreadystatechange(e) { xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
@ -61,7 +69,8 @@ function getPdf(arg, callback) {
var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse || var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse ||
xhr.responseArrayBuffer || xhr.response); xhr.responseArrayBuffer || xhr.response);
callback(data); callback(data);
} else if (params.error) { } else if (params.error && !calledErrorBack) {
calledErrorBack = true;
params.error(e); params.error(e);
} }
} }