0
page1.php調用Ajax從page2.php獲取Treeview(之所以在這裏使用Ajax,是因爲Treeview基於db改變了)。 Treeview是一個Jquery插件。因此,所有需要Treeview的Jquery庫都已經在page1.php中導入了。jquery插件不能使用Ajax
但是,Jquery庫並未觸發。 console.log($("#browser").treeview());
顯示空的Jquery()。
有沒有人可以幫助我?非常感謝!第1頁
--Ajax部分---
<head>
<script src="jquery.treeview.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#browser").treeview();
console.log($("#browser").treeview());
//show Jquery()-means the jquery.treeview didn't called
});
</script>
<script type="text/javascript">
function showTreeview()
{
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)
{
document.getElementById("treemenu").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","page2.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="treemenu">
</div>
</body>
#browser元素在哪裏?我沒有看到它在你的標記。 – Redtopia 2012-03-28 14:53:36
#browser元素在page2.php – Acubi 2012-03-28 14:56:43
您的示例不完整,因此很難說出發生了什麼。我沒有看到任何將調用showTreeview()函數的代碼,所以我不確定爲什麼在這個例子中。正如ShankarSangoli所說,如果#browser位於page2.php中,則需要從該頁面實例化樹視圖。你可以使用$(document).ready();在那個頁面裏面去做。 – Redtopia 2012-03-28 15:47:49