Phonegap + head.js on iOS, won't work?

447 Views Asked by At

I'm using Phonegap 2.1.0 on iOS. In my main.html-file I'm loading some html using jQuery.

However, one of the html-files I'm loading has its own Javascript that loads other files, in the same way ($.ajax etc.). Phonegap in Android loads these files and executes the Javascript in them, but iOS does not.

Example: index.html:

<...>
  <body>
    <script>
      $(document).on('pageinit', function() {
        $.ajax({
          url: 'some.url',
          success: function(data, status, jqxhr) {
            $("#some-div").html(data);
          },
          error: function(jqxhr, status, error) {}
        });
      });
    </script>
  </body>
</...>

some.url:

<script type="text/javascript">
  head.js(
    "config-file.js",

    function() {
      $.ajax({
        url: PATH + 'some-other.url', // PATH? see below
        success: function(data, status, jqxhr) {
          $("#some-div").html(data);
        },
        error: function(jqxhr, status, error) {}
      });
    });
</script>

config-file.js: var PATH = 'mypath';

some-other.url: fails to load in iOS

All loaded files are served from the same domain.

Again, the code above works in Android. Any ideas why iOS fails to do this, and how to solve it? Is it head.js? (0.9.6)

1

There are 1 best solutions below

1
On

Since you are using jQuery Mobile, which depends on jQuery anyways, why not just use jQuery to do the file loading ?

$.getScript('path')
   .done(function(){
       ...
});

Otherwise you could also give HeadJS v0.99 a try to see if it fixes your issues.