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 2012/06/21 02:00:56 UTC

[5/12] js commit: [CB-276] getJSON on local file, resolve path to app/www/* when XHR to local file, and return string data

[CB-276] getJSON on local file, resolve path to app/www/* when XHR to local file, and return string data


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/170affbd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/170affbd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/170affbd

Branch: refs/heads/master
Commit: 170affbd5fe60e8bbc97cc4dd452386a6826070b
Parents: 745b196
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Jun 11 18:10:51 2012 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Jun 13 09:14:09 2012 -0700

----------------------------------------------------------------------
 lib/wp7/plugin/wp7/XHRPatch.js |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/170affbd/lib/wp7/plugin/wp7/XHRPatch.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/XHRPatch.js b/lib/wp7/plugin/wp7/XHRPatch.js
index 14a8575..a16c4ef 100644
--- a/lib/wp7/plugin/wp7/XHRPatch.js
+++ b/lib/wp7/plugin/wp7/XHRPatch.js
@@ -105,12 +105,18 @@ if (!docDomain || docDomain.length === 0) {
                 return this.wrappedXHR.open(reqType, uri, isAsync, user, password);
             }
             else {
+                console.log("url is " + uri);
                 // x-wmapp1://app/www/page2.html
                 // need to work some magic on the actual url/filepath
                 var newUrl = uri;
                 if (newUrl.indexOf(":/") > -1) {
                     newUrl = newUrl.split(":/")[1];
                 }
+                // prefix relative urls to our physical root
+                if(newUrl.indexOf("app/www/") < 0)
+                {  
+                    newUrl = "app/www/" + newUrl;
+                }
 
                 if (newUrl.lastIndexOf("/") === newUrl.length - 1) {
                     newUrl += "index.html"; // default page is index.html, when call is to a dir/ ( why not ...? )
@@ -140,6 +146,15 @@ if (!docDomain || docDomain.length === 0) {
         responseXML: "",
         onResult: function (res) {
             this.status = 200;
+            console.log("onResult XHR :: " + res);
+            console.log("typeof = " + typeof res);
+            if(typeof res == "object")
+            {   // callback result handler may have already parsed this from a string-> a JSON object,
+                // if so, we need to restore it's stringyness, as handlers are expecting string data.
+                // especially if used with jQ -> $.getJSON
+                console.log("re-stringing the guitar");
+                res = JSON.stringify(res);
+            }
             this.responseText = res;
             this.responseXML = res;
             this.changeReadyState(this.DONE);