你好我還是新的阿賈克斯我想在不同的地方顯示2個數據。ajax顯示2個數據請求onclick
這裏的代碼
<li onclick="showPost(this.value);" value="*digit*" >lala</li>
的JavaScript
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
function showPost(hal)
{
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("gallekanan").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../wp-content/themes/koolfort/example.php?pal="+hal,true);
xmlhttp.send();
showJudul(hal);
}
function showJudul(hal)
{
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("eventjudul").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../wp-content/themes/koolfort/example1.php?pal="+hal,true);
xmlhttp.send();
}
</script>
當我運行的代碼只是showJudul運行和showPost被中止。
首先,不要使用全局變量,使用'var'。其次,我在想... =)) – 2012-04-05 08:47:19