[英]Syntax error loading content dynamically in html page with ajax
我試圖在我的HTML div中動態加載一些內容。 如果嘗試這樣做,則會出現錯誤:語法錯誤HOME。 (這是在div中應可見的內容)。
HTML:導航欄:
<li><a href="#" onclick="replaceContent('home.html')">Home</a></li>
需要填寫的Div:
<div id="pagepanel"></div>
home.html
HOME.
Javascript:
function replaceContent(newDiv) {
var xmlHttp = createXMLHttp();
xmlHttp.onreadystatechange = function(){replace(xmlHttp);}
xmlHttp.open("GET", newDiv, true);
xmlHttp.send(null);
}
function replace(xmlHttp) {
if (xmlHttp.readyState==4 && xmlHttp.status==200){
document.getElementById("pagepanel").innerHTML=xmlHttp.responseText;
}
alert(xmlHttp.responseText);
}
function createXMLHttp() {
var xmlHttp;
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}else{
alert("Please upgrade your browser! Your browser does not support AJAX!");
}
return xmlHttp;
}
由於缺少分號,因此發生了錯誤。
onclick="replaceContent('home.html')";>Home</a></li>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.