0

さて、私はこれに数時間苦労しています。私はajaxを使用してサイトのdivをphpコードで更新していますが、関数内のパラメーターを外部のjavascriptファイルから送信して、正しいリンクを更新しようとしています(複数のドロップダウンボックスがあります)

例:これは私の選択ボックスです

<script type='text/javascript' src='ajax.js'></script>//include ajax file
<select onchange='MakeRequest(raceupdate);
        this.options[this.selectedIndex].value;'> //so no use of a button is needed to auto link to anchor tag
        <option>Deathmateched</option>
    <?php
        dmList()
        ?>

 </select>

次に、私の外部ajax関数MakeRequest()。

function MakeRequest(value)
{
    var linkInfo = "teleport.php?call=" + value;//create appropriate link depending on function parameters  
    var xmlHttp = getXMLHttp();

    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            HandleResponse(xmlHttp.responseText);
        }
    }     

    xmlHttp.open("GET", linkInfo, true); //update page using link info variable created above
    xmlHttp.send(null);

}

ご覧のとおり、この関数にテキストを渡そうとしていますが、どこかで失敗しているようです。

4

1 に答える 1

1

「this」を渡すようにタグを設定することをお勧めします。グローバルでない限り、raceupdate変数がどこで宣言されているかわかりません...その場合は、その変数で何をしているのかを表示する必要があります。

<select onchange='MakeRequest(this);'> 
    <option>Deathmateched</option>
    <?php
        dmList();
    ?>

そのようにした場合は、この関数を次のように変更する必要があります。

    function MakeRequest(element)
    {
    var linkInfo = "teleport.php?call=" + element.value;//create appropriate link depending on function parameters  
    var xmlHttp = getXMLHttp();

    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            HandleResponse(xmlHttp.responseText);
        }
    }     

    xmlHttp.open("GET", linkInfo, true); //update page using link info variable created above
    xmlHttp.send(null);

}

そして、あなたはここで何をしようとしていますか?

this.options[this.selectedIndex].value;

あなたのコメントでは、アンカータグにジャンプしたいと言っているように見えますか?もしそうなら、あなたは次のようなことをしたいと思うでしょう

var anchorTag = document.getElementID("YOUR_ANCHOR_TAG_ID");
anchorTag.focus();
于 2012-05-31T01:07:20.900 に答える