0

Basically, im trying to use XMLHttpRequest to load a .json file i've included in my working files in XDK. I'm loading the filename as the url, so for example im loading

url = "MyFile.json" 
xhr.open( 'GET', url, true );

Then i look at responseText in an onreadystatechange function when readystate is done and status indicates everythings finished. Normally when I run stuff in my desktop browser or even in the XDK emulator for any device, everything works as intended. The problem is that when I package the project using crosswalk, something seems to be going wrong and responseText returns null/false/undefined whatever, indicating SOMETHING (but i'm not sure what) didn't work, and my file fails to load.

This may be a little vague but i'm doing my best with what i understand. XDK and crosswalk are new to me and i'm very uncertain where the issue lies. After building and rebuilding my application many times without any idea how or why things are messing up, i'm hoping someone can help me out. perhaps its something simple like the url of these files being different, or maybe its something complicated that requires cross-origin stuff. I don't really know and i've searched quite a bit with nothing coming up so far.

I'm using three.js and specifically this problem seems to be with the JSONLoader component, but really i don't mind rewriting any loader, i just need the xmlHttpRequest to get me the file.

UPDATE

Doing a little bit of digging I feel like i'm on the track but theres some small thing i'm missing. responseText is empty, but other than that im already following all the guidelines i can find online for loading files from the assets/www/ folder. Is the issue perhaps with me loading a file with the extension ".json" or ".js"?

Quazi
  • 129
  • 1
  • 7
  • That should work. Which device are you testing on that is having the issue? Is it the emulator or a physical device? Also, remove any references to xhr.js - that is for the legacy containers and no longer needed. – Ian Maffett Jan 12 '15 at 13:59
  • Try using the Debug tab for your debugging, it is running a version of Crosswalk. Or, add the "debuggable" equals "true" directive to your Crosswalk build and debug remotely. See the "blank cordova template" for an example of that file (*.additions.xml file > https://github.com/gomobile/template-a-blank-cordova/blob/master/intelxdk.config.additions.xml). Also, if you are using App Framework directly or via App Designer, make sure you have the latest version of the App Framework library in your project. Latest files are here > https://github.com/01org/appframework/tree/master/build – xmnboy Jan 12 '15 at 16:57
  • Device is an actual Nexus 5. With that said, the emulator for every device available in XDK works fine, but the file loading just fails for some reason in the built application on the actual devices. I've asked people to test it on a variety of android devices and it's the same problem. – Quazi Jan 13 '15 at 03:40
  • Also: I'm not actually referencing some xhr.js file (i don't think), it's a "var xhr" in the function. Just how the three.js loader was written. – Quazi Jan 13 '15 at 03:46

1 Answers1

0

I figured out a bit more about the problem (i'm having trouble specifically with loading assets in phonegap/cordova, since my project uses cordova.js, and is built in construct 2, then exported to crosswalk via XDK) I have no real answer yet but i feel i need to close this question and ask a more pertinent one somewhere else. For the time being the issue is either A. a bug with the built in implementation of XMLHttpRequest which crosswalk / cordova are using on the android devices or B. an issue with my practices. Everywhere online says what i'm doing should work, and is inherently designed to work in crosswalk, so i really don't know where the problem lies atm.

Quazi
  • 129
  • 1
  • 7