2012-05-31 24 views
0

我有兩個div在我的page.the第一個div包含一個導航欄有兩個選項。 我想要做的是當我點擊導航欄中的選項,我想要相應的HTML文件加載在第二個div。 我如何做這個。請幫助。我如何在div中插入外部html文件在jquery移動

這裏是我到目前爲止的代碼..

<!DOCTYPE HTML> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Test Document</title> 
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" /> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> 
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> 

<script type = "text/javascript"> 
function loadSurveyPage() 
{ 
alert("Survey"); 
$('#myBody').load('survey.html #myQuestions'); 
} 

function howToSurvey() 
{ 
alert("How to Survey"); 
$('#myBody').load('howToSurvey.html #myQuestions'); 
} 
</script> 
</head> 
<body id="myBody"> 



<div data-role="page" id="indexPage"> 

<div data-role="header" data-position="fixed"> 
<div data-role="navbar" id="navbar"> 
<ul> 
    <li><a href="#" rel="external" onclick="howToSurvey()">How To Take The Survey</a></li> 
    <li><a href="#" onclick="loadSurveyPage()">Take Survey</a></li>  
</ul> 
</div> 
</div> 

<div data-role="content" id="myQuestions"></div> 
</div> 



</body> 
</html> 

我得到當我點擊該選項下面的錯誤..

的XMLHttpRequest無法加載文件:/// C:/用戶/ SP05 /Desktop/Self/TMS/testForTab/howToSurvey.html。 Access-Control-Allow-Origin不允許Origin null。

回答

1
  1. 您應該使用本地Web服務器進行開發(適用於Windows的f.ex.IIS)。您在這裏遇到的問題可能是安全問題。
  2. 您正在使用.load()方法錯誤。 selector參數指向返回的html上的元素。使用獲得()或。員額()代替:http://api.jquery.com/category/ajax/shorthand-methods/
0

我面臨一些跨域問題......我跑了WAMP的服務器在同一個項目和它的工作完全確定..