Skip to content

Commit

Permalink
[CB-276] getJSON on local file, resolve path to app/www/* when XHR to…
Browse files Browse the repository at this point in the history
… local file, and return string data
  • Loading branch information
purplecabbage committed Jun 12, 2012
1 parent 79f8fb9 commit 18a6917
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/wp7/plugin/wp7/XHRPatch.js
Expand Up @@ -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 ...? )
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 18a6917

Please sign in to comment.