2017-03-06 66 views
0

我在腳本中編寫了一個代碼,如下所示。使用腳本將內容發送到其他頁面

function myFunction(a) { 
    var k=a; 
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function() { 
    if (this.readyState == 4 && this.status == 200) { 
     document.getElementById("ques").innerHTML = this.responseText; 
    } 
    }; 
    xhttp.open("GET", "retrieveQuestion.php?question=" +a, true); 
    xhttp.send(); 
    var q="<td><input type='text' name='answer' id='ans' placeholder='submit your answer here'/></td>" ; 
    document.getElementById("t2").innerHTML=q; 
    var answ = document.getElementById("ans").value; 
    var z="<td align='center'><input type='button' value='submit' onclick='myfunc1(k,answ)'/></td>"; 
    document.getElementById("t3").innerHTML=z; 
} 

function myfunc1(q1,a1) 
{ 
    xhttp.open("GET", "checkanswer.php?question=" +q1 + "&a1=" +a1, true); 
    xhttp.send(); 
} 

現在,當我點擊提交按鈕,它並沒有重定向到checkanswer.php 誰能幫助我在這個問題上。

回答

0

使用xhttp.open發送背景請求到checkanswer.php,而不是實際重定向到它。您需要使用類似window.location的東西。

相關問題