Android,Phonegap和jQueryMobile - 错误连接到服务器失败了“www / assets / index.html”

时间:2013-02-02 10:02:43

标签: android cordova jquery-mobile

我尝试过以下代码,但我收到错误与服务器的连接未能成功“www / assets / index.html”

<!DOCTYPE html>
<html>
   <head>
     <style type="text/css">
        li span
         {
            font-weight: normal;
         }
     </style>
   <title> Sample App using jQuery Mobile</title>
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
      <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
      <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
   <head>
   <body>
      <div data-role="page" id="car">
         <div data-role="header" data-postion="fixed">
            <h1> Cars</h1>
            <h1 id="blogheader">Loading...</h1>
         </div>
         <div data-role="content">
            <ul data-role="listview" data-inset="true" id="contentListView">
            </ul>
         </div>
         <div data-role="footer" data-position="fixed">
             <h1> Footer </h1>
         </div>
     </div>

 <script type="text/javascript" charset="utf-8">
    $(function(){
       var serviceUrl='http://mysite:81/Service.asmx/ShowListViewData';
       $.ajax({
         url:serviceUrl,
         success:function(xml){
         setTimeout(
         function(){
            $(xml).find( "newset" ).each(function(){
                carName  = $(this).find('ItemName').text();
                description  = $(this).find('ItemDescription').text();
                $('#contentListView').append('<li><a href="#"><h3>Car type:<span> '+carName+'</span></h3><p>' + description + '</p></a></li>');
            });
        $('#contentListView').listview('refresh');
       }
       ,100);
      },
       error:function(){
      },
       dataType:"xml"
   });
 });
 </script>
 </body>
</html>
有趣的是,它之前的工作正常。但现在我收到了这个错误。事实上,我甚至尝试过这种方法[ super.setIntegerProperty(“loadUrlTimeoutValue”,60000); ],但尚未解决。它删除了错误,但远程服务器的数据没有加载..请帮帮我..

感谢。

1 个答案:

答案 0 :(得分:1)

对于迟到的回复感到抱歉..代码有...唯一的区别是我将所有css和js文件都包含在我的项目中而不是从CDN引用

<!DOCTYPE html>
<html>
   <head>
     <style type="text/css">
        li span
         {
            font-weight: normal;
         }
     </style>
   <title> Sample App using jQuery Mobile</title>
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
     <link href="styles/jquery.mobile-1.0.min.css" />
    <script src="scripts/jquery-1.6.4.min.js"></script>
   <script src="scripts/jquery.mobile-1.0.min.js"></script>
  <head>
   <body>
      <div data-role="page" id="car">
         <div data-role="header" data-postion="fixed">
            <h1> Cars</h1>
            <h1 id="blogheader">Loading...</h1>
         </div>
         <div data-role="content">
            <ul data-role="listview" data-inset="true" id="contentListView">
            </ul>
         </div>
         <div data-role="footer" data-position="fixed">
             <h1> Footer </h1>
         </div>
     </div>

 <script type="text/javascript" charset="utf-8">
    $(function(){
       var serviceUrl='http://mysite:81/Service.asmx/ShowListViewData';
       $.ajax({
         url:serviceUrl,
         success:function(xml){
         setTimeout(
         function(){
            $(xml).find( "newset" ).each(function(){
                carName  = $(this).find('ItemName').text();
                description  = $(this).find('ItemDescription').text();
                $('#contentListView').append('<li><a href="#"><h3>Car type:<span> '+carName+'</span></h3><p>' + description + '</p></a></li>');
            });
        $('#contentListView').listview('refresh');
       }
       ,100);
      },
       error:function(){
      },
       dataType:"xml"
   });
 });
 </script>
 </body>
</html>

感谢。