title: My Javascript Ajax request works in Phonegap index.html but not in any other pages, how can I fix this?
body: <p>The request I have made works in the index.html file but not in any others which is greatly frustrating. I think it is to do with the onDeviceReady function but I am not sure how to change or fix this?</p>
  
  <p>Here is the separate page (not index.html) code:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0;" /&gt;
      &lt;script src="cordova-1.8.1.js"&gt;&lt;/script&gt;
      &lt;script src="js/jquery-1.7.2.min.js"&gt;&lt;/script&gt;
      &lt;script src="js/load-whites.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" /&gt;
      &lt;script src="http://code.jquery.com/jquery-1.7.1.min.js"&gt;&lt;/script&gt;
      &lt;script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  
      &lt;div data-role="page" id="whites"&gt;
  
          &lt;div data-role="header" data-position="fixed"&gt;
              &lt;h1&gt;White Wines&lt;/h1&gt;
          &lt;/div&gt;
  
          &lt;div data-role="content"&gt;
  
              &lt;div data-role="collapsible-set" data-theme="c" data-content-theme="d"&gt;
                  &lt;div id="whites"&gt;&lt;/div&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the request that works for the index.html file but not for any other .html files in my phonegap project (Cordova 1.8.1). How could I change it so that it does work? the file below is load-whites.js:</p>
  
  <pre><code>$(document).ready(function(){
                $(document).bind('deviceready', function(){
                                 onDeviceReady();
                                 });
  
                function yourCallback(button) {
                if (button == 2) {
                dataRequest();
                }
                }
  
                function dataRequest() {
                var output = $('#whites').text('Loading white wines and their deta1ils, please wait...');
  
                $.ajax({
                       url: 'http://localhost/whites.php',
                      dataType: 'jsonp',
                       jsonp: 'jsoncallback',
                       timeout: 5000,
                       success: function(data, status){
                       output.empty();
  
                  $.each(data, function(i,item){
  
                         var whites =  '&lt;div data-role="collapsible"&gt;&lt;h3&gt;'+item.Name+'&lt;/h3&gt;'
                                      +'&lt;b&gt;Price:&lt;/b&gt; £'+item.Price+'&lt;br /&gt;'
                                      +'&lt;b&gt;Vintage:&lt;/b&gt; '+item.Vintage+'&lt;br /&gt;'
                                      +'&lt;b&gt;Country:&lt;/b&gt; '+item.Country+'&lt;br /&gt;'
                                      +'&lt;b&gt;Grape:&lt;/b&gt; '+item.Grape+'&lt;br /&gt;'
                                      +'&lt;b&gt;Alcohol:&lt;/b&gt; '+item.Alcohol+'%&lt;br /&gt;&lt;br /&gt;'
                                      +item.Description+'&lt;/p&gt;&lt;/div&gt;';
  
  
  
                         output.append(whites);
  
                    $('#whites').trigger('create');
  
  
                         });
                       },
                       error: function(){
                       output.text('The Wines could not be loaded at this time.');
                       navigator.notification.confirm(
                                  'Please check your internet connection. Would you like to retry?',
                                  yourCallback,
                                  'Something went wrong',
                                  'No,Yes'
                                      );
                       }
                       });
                }
  
  
                dataRequest();
                });
  </code></pre>
  
  <p>Any help would be greatly appreciated. Thanks again.</p>