[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/18a6917f Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/18a6917f Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/18a6917f Branch: refs/heads/master Commit: 18a6917fa6737ae498535999d0e0046b50670ff7 Parents: 79f8fb9 Author: Jesse MacFadyen <[email protected]> Authored: Mon Jun 11 18:10:51 2012 -0700 Committer: Jesse MacFadyen <[email protected]> Committed: Mon Jun 11 18:10:51 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/18a6917f/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);
