2017-03-06 73 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的东西。

相关问题