You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/03/27 19:45:11 UTC
[4/6] js commit: [CB-2806] Fix plugin loading when XHR doesn't return
valid JSON
[CB-2806] Fix plugin loading when XHR doesn't return valid JSON
Take two!
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/32b9e1c3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/32b9e1c3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/32b9e1c3
Branch: refs/heads/2.6.x
Commit: 32b9e1c30649d228faa397bbc6216548c437742c
Parents: 5f56a0d
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Mar 26 09:54:30 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Mar 26 10:40:55 2013 -0400
----------------------------------------------------------------------
lib/scripts/plugin_loader.js | 19 +++++++------------
1 files changed, 7 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/32b9e1c3/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index 03a7381..8e4161d 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -94,24 +94,19 @@
// Try to XHR the cordova_plugins.json file asynchronously.
var xhr = new context.XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState != 4) { // not DONE
- return;
- }
-
+ xhr.onload = function() {
// If the response is a JSON string which composes an array, call handlePluginsObject.
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
- if (this.status == 200 || this.status == 0) {
- var obj = JSON.parse(this.responseText);
- if (obj && obj instanceof Array && obj.length > 0) {
- handlePluginsObject(obj);
- } else {
- finishPluginLoading();
- }
+ var obj = JSON.parse(this.responseText);
+ if (obj && obj instanceof Array && obj.length > 0) {
+ handlePluginsObject(obj);
} else {
finishPluginLoading();
}
};
+ xhr.onerror = function() {
+ finishPluginLoading();
+ };
xhr.open('GET', 'cordova_plugins.json', true); // Async
xhr.send();
}(window));