基本AJAX或XMLHttpRequest调用的(而不是诉诸库):
<script>
function loadNavigation() {
var xmlhttp;
if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState==4 && xmlhttp.status==200) {
//--- change this to your navigation element
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
//--- change the filename to the navigation file
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
当指定文件名只要意识到上述内容将在平面文件系统中运行,并且您可能需要指定导航文件的完整URL路径,因为您使用的是多级文件结构 - 如果有意义的话。
您可以将导航块放置在单独的文件(所有HTML代码)中。然后,使用AJAX将文件加载到页面中。 – jeff
请参阅下面的答案,了解您可以使用的基本AJAX功能。 – jeff