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:
commit
377a96dda7
15
src/core.js
15
src/core.js
@ -52,8 +52,16 @@ function getPdf(arg, callback) {
|
||||
if ('progress' in params)
|
||||
xhr.onprogress = params.progress || undefined;
|
||||
|
||||
if ('error' in params)
|
||||
xhr.onerror = params.error || undefined;
|
||||
var calledErrorBack = false;
|
||||
|
||||
if ('error' in params) {
|
||||
xhr.onerror = function errorBack() {
|
||||
if (!calledErrorBack) {
|
||||
calledErrorBack = true;
|
||||
params.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
|
||||
if (xhr.readyState === 4) {
|
||||
@ -61,7 +69,8 @@ function getPdf(arg, callback) {
|
||||
var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse ||
|
||||
xhr.responseArrayBuffer || xhr.response);
|
||||
callback(data);
|
||||
} else if (params.error) {
|
||||
} else if (params.error && !calledErrorBack) {
|
||||
calledErrorBack = true;
|
||||
params.error(e);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user