我目前有三个存储的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变量,如$
符号?
答案 0 :(得分:1)
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']