From 813b5e78b0624e42bb2649694cd694f5c793d563 Mon Sep 17 00:00:00 2001 From: benbro Date: Wed, 18 Jul 2012 21:41:36 +0300 Subject: [PATCH 1/3] Prevent the error callback from being called twice --- src/core.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 409ae060d..27d5551d1 100644 --- a/src/core.js +++ b/src/core.js @@ -52,8 +52,12 @@ function getPdf(arg, callback) { if ('progress' in params) xhr.onprogress = params.progress || undefined; - if ('error' in params) + var calledErrorBack = false; + + if ('error' in params && !calledErrorBack) { + calledErrorBack = true; xhr.onerror = params.error || undefined; + } xhr.onreadystatechange = function getPdfOnreadystatechange(e) { if (xhr.readyState === 4) { @@ -61,7 +65,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); } } From f60d7c564f6c067d8bf0b5e5ab4ef4700a207073 Mon Sep 17 00:00:00 2001 From: benbro Date: Wed, 18 Jul 2012 22:05:55 +0300 Subject: [PATCH 2/3] Moved the check for calledErrorBack inside the xhr.onerror function --- src/core.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core.js b/src/core.js index 27d5551d1..1b3d91dbd 100644 --- a/src/core.js +++ b/src/core.js @@ -54,9 +54,12 @@ function getPdf(arg, callback) { var calledErrorBack = false; - if ('error' in params && !calledErrorBack) { - calledErrorBack = true; - xhr.onerror = params.error || undefined; + if ('error' in params) { + xhr.onerror = function errorBack() { + if (!calledErrorBack) { + calledErrorBack = true; + params.error(); + } } xhr.onreadystatechange = function getPdfOnreadystatechange(e) { From 97e72d58649e80196c1eef79d4e73ded3ed65893 Mon Sep 17 00:00:00 2001 From: benbro Date: Sat, 21 Jul 2012 00:51:36 +0300 Subject: [PATCH 3/3] Add missing bracket --- src/core.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core.js b/src/core.js index 1b3d91dbd..2b9481041 100644 --- a/src/core.js +++ b/src/core.js @@ -60,6 +60,7 @@ function getPdf(arg, callback) { calledErrorBack = true; params.error(); } + } } xhr.onreadystatechange = function getPdfOnreadystatechange(e) {