结合AJAX请求来加载带有变量的新页面


Combine AJAX request to load new page with variables

我目前有三个存储的JS变量(wordChoiceOne, wordChoiceTwo, wordChoiceThree)。现在我已经存储了这些,我想运行一个名为saveUsername()的函数。这个函数应该执行以下操作:

将上面的jQuery变量传递给PHP 将文件register-form.php加载到div register-login-form

所以我目前有以下AJAX请求,但这只处理表单的重新加载。我以前从未将jQuery与PHP结合过,所以我如何添加这部分来传递三个变量?

function saveUsername(wordChoiceOne, wordChoiceTwo, wordChoiceThree){
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("login-register-form").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","register-form.php",true);
xmlhttp.send();
}

我该添加什么来传递三个变量并将它们转换为PHP变量,如$符号?

function saveUsername(wordChoiceOne, wordChoiceTwo, wordChoiceThree){
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("login-register-form").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","register-form.php?one="+wordChoiceOne+"&two="+wordChoiceTwo+"&three="+wordChoiceThree,true);
xmlhttp.send();
}
然后PHP端,使用$_GET['one'], $_GET['two']$_GET['three']