2
這是我的js代碼Ajax代碼不工作
function load(div_tag,thefile)
{
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById(div_tag).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', thefile, true);
xmlhttp.send();
}
,這我的PHP代碼
echo '<div style="float:left; margin-left:2px; margin-top:17px; background:#666; text-align:center; width:auto;"><a href="#div" onclick="load(\'div\',\'include/comment_form.php\')" style="text-decoration:none;"><b style="color:white;">Add comment</b></a></div>';
echo '<div id="div" align="left" style="clear:both;"></div>';
的問題是它的工作在XAMPP,但它並不在我的網站工作。我是一個首發,請幫助我。
任何錯誤信息? – Sirko
它在哪裏*不*工作?例如''a''標籤onclick'取決於* load *的返回值 - 它不返回任何東西,因此依賴於瀏覽器(使其返回* true *來激活重定向)。 –
如何以及在哪裏調用'load'函數? – ShuklaSannidhya