Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[CB-2806] Fix plugin loading when XHR doesn't return valid JSON

Take two!
  • Loading branch information...
commit 32b9e1c30649d228faa397bbc6216548c437742c 1 parent 5f56a0d
Ian Clelland authored March 26, 2013 agrieve committed March 26, 2013

Showing 1 changed file with 7 additions and 12 deletions. Show diff stats Hide diff stats

  1. 19  lib/scripts/plugin_loader.js
19  lib/scripts/plugin_loader.js
@@ -94,24 +94,19 @@
94 94
 
95 95
     // Try to XHR the cordova_plugins.json file asynchronously.
96 96
     var xhr = new context.XMLHttpRequest();
97  
-    xhr.onreadystatechange = function() {
98  
-        if (this.readyState != 4) { // not DONE
99  
-            return;
100  
-        }
101  
-
  97
+    xhr.onload = function() {
102 98
         // If the response is a JSON string which composes an array, call handlePluginsObject.
103 99
         // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
104  
-        if (this.status == 200 || this.status == 0) {
105  
-            var obj = JSON.parse(this.responseText);
106  
-            if (obj && obj instanceof Array && obj.length > 0) {
107  
-                handlePluginsObject(obj);
108  
-            } else {
109  
-                finishPluginLoading();
110  
-            }
  100
+        var obj = JSON.parse(this.responseText);
  101
+        if (obj && obj instanceof Array && obj.length > 0) {
  102
+            handlePluginsObject(obj);
111 103
         } else {
112 104
             finishPluginLoading();
113 105
         }
114 106
     };
  107
+    xhr.onerror = function() {
  108
+        finishPluginLoading();
  109
+    };
115 110
     xhr.open('GET', 'cordova_plugins.json', true); // Async
116 111
     xhr.send();
117 112
 }(window));

0 notes on commit 32b9e1c

Please sign in to comment.
Something went wrong with that request. Please try again.