6

I'm trying to get a simple web project running via PhoneGap. The site uses RequireJS to load modules asynchronously. It also has Handlebars templates which I'm loading via the RequireJS text plugin.

The site works fine when served from a local HTTP server. However on the device it fails to render. Debugging on PhoneGap is tricky (though can be done to some extent), but as far as I can tell, the issue is related to the loading of these templates using the RequireJS text plugin.

The weinre-based debugger provided by PhoneGap shows an error string in the console:

JSCallback Error: Request failed.

Can anyone recommend a solution?

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • Was having a similar issue, then it turned out to be my dumbness :) I didn't copy over my template folder.... So txt plugin for rquirejs works fine for me under cordova. Found this nice tutorial as well... http://www.appliness.com/getting-started-with-html-mobile-application-development-using-jquery-mobile-requirejs-and-backbonejs/ – Krym Sep 14 '12 at 12:25
  • 1
    One tricky thing I have noticed, is that in phonegap running on iOS device, the paths used in require/define array are case sensitive, while in Chrome desktop browser, the case does not seem to matter. Could be something like that? – Paul Hoenecke Jan 23 '13 at 19:33
  • Though I have run in to this issue before and was testing on Windows Phone 7 and on Android, this should give you some insight. http://stackoverflow.com/questions/13038573/phonegap-windows-phone-7-dynamic-html-loading-and-cross-domain-calls-using-jquer/13093715#13093715 Hope that helps. Cheers! Suj – Sujesh Arukil Mar 08 '13 at 21:41
  • 1
    "On the device", can you be more specific?? Android/iOS? This error is thrown when the request's statuscode `!=` 200 or 404, which will probably be either a 500(internal error) or a 403(unauthenticated). Are the templates on a remote server or are they included in your PG `www` folder? I've seen these errors before, where someone forgot to grant `INTERNET`-permission on Android.. – Rob Mar 20 '13 at 11:12

2 Answers2

0

the text plugin can create problems when, for example, the templates are hosted on a different domain from the one which is running the javascript. in that case, due to security restrictions in cross origin requests, the plugin will assume that you are downloading the compiled version of your templates, and append .js to the file locator.

if you have control of the server, you can check if the wrong path is requested.

danza
  • 11,511
  • 8
  • 40
  • 47
0

Use safari to debug the site on your mobile device / simulator, and it should tell you exactly which request is failing in the network tab.

See http://webdesign.tutsplus.com/tutorials/workflow-tutorials/quick-tip-using-web-inspector-to-debug-mobile-safari/

pfrank
  • 2,090
  • 1
  • 19
  • 26