2012-11-19 24 views
1

我想弄清楚如何使用$.mobile.loadPage。我在加載外部頁面時遇到問題。這裏是我的代碼片段:jquery mobile loadPage

<!DOCTYPE HTML> 
<html> 
    <head> 
     <title>test</title> 
     <meta name="viewport" content="width=device-width; initial-scale=1"> 
     <meta http-equiv="cache-control" content="no-cache"> 
     <meta http-equiv="pragma" content="no-cache"> 

     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 

     <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
     <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 
     <script> 
     function loadme() { 
      $.mobile.loadPage("external.html", {pageContainer: $('#homecontent')});    
     }   
     /////////////////////////////////////////////////////////////////// 
     $(document).bind ("pagebeforeload", function (event, data) { 
      alert ("ext - pagebeforeload"); 
     }); 
     $(document).bind ("pageload", function (event, data) { 
      alert ("ext - pageload"); 
     }); 
     $(document).bind ("pageloadfailed", "#page2", function (event, data) { 
      alert ("pageloadfailed"); 
     }); 
     </script> 
    </head> 
    <body> 

     <div data-role="page" id="home"> 
     <div data-role="header" data-id="myheader" data-position="fixed"> 
      <h1>Home Page</h1> 
     </div> 
     <div data-role="homecontent"> 
      <span onclick="loadme();" style="cursor:pointer;">load me</span> 
     </div> 
     <div data-role="footer" data-id="myfooter" data-position="fixed"> 
      <h1>footer</h1> 
     </div> 
     </div> 

     <div data-role="page" id="page2" data-add-back-btn="true"> 
     <div data-role="header" data-id="myheader" data-position="fixed"> 
      <h1>Page 2</h1> 
     </div> 
     <div data-role="page2content"> 
     </div> 
     <div data-role="footer" data-id="myfooter" data-position="fixed"> 
      <h1>footer</h1> 
     </div>  
     </div> 
    </body> 
</html> 

下面是我

的XMLHttpRequest無法加載 文件中的錯誤:/// C:/Documents%20and%20Settings/.../external。 HTML。 Access-Control-Allow-Origin不允許訪問原產地 。

我在本地桌面上測試。歡迎任何建議。在此先感謝

回答

0

您的瀏覽器有一些限制,防止某些類型的交互將本地文件。假設你使用的是Chrome,你需要添加一個命令行選項來啓用這種類型的訪問。在Windows中,它將是:

chrome.exe --allow-file-access-from-files