2

これは私のjsコードです

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で機能しているのに、私のWebサイトでは機能していないことです。私はスターターです。助けてください。

4

1 に答える 1

2

成功したコメントに合うように答えてください:

関数はタグのハンドラー内にあるため、trueまたはfalseload()の値を返す必要があります。何も返さないため、結果はブラウザによって異なります。onclick<aload()

trueを返すだけでload()、アンカーリダイレクトがアクティブになります

function load(div_tag,thefile)
{
    ...
    xmlhttp.open('GET', thefile, true);
    xmlhttp.send();

    return true;
}
于 2013-02-03T14:10:32.600 に答える