George_Fal 2015-08-12 19:04 采纳率: 0%
浏览 31

Phonegap多页

I'm currently working on an application in cordova. Since I have more pages I tried to add a menu. On the first page (index.html) there is some output, on the second file (settings.html) I want to make a Ajax-Request to a external server.

In the <head>-Tag all stylesheets and jQuery and Cordova is included. In the <body>-Tag some Ajax-calls are made.

<head>

<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
<script type="text/javascript" src="cordova.js"></script>
</head>

<body onload="onLoad();">    
<div data-role="controlgroup" data-corners="false">
  <a href="index.html">Home</a>
  <a href="settings.html">Settings</a>
</div>
<!-- Ajax Requests -->
</body>

If I hit Settings I get to the html-page and the code will be displayed, but the code jQuery/js-code will not be executed. (I tried an alert, but it's not working)

Can you tell me what possibilities I have to include another page with working js-code?

Thanks!

  • 写回答

2条回答 默认 最新

  • weixin_33697898 2015-08-12 19:13
    关注

    You need to include a script that will fire when the page is fully loaded into the DOM.

     <script>
          $(document).ready(function(){
              -- call your$.ajax({}) here --
          });
     </script>
    

    OR

     <script>
      (function(){
         call your $.ajax({}) here --
       }();
     </script>
    
    评论

报告相同问题?