如何使用Native Javascript将Ajax PHP字符串重定向到新URL?

时间:2018-01-04 03:49:38

标签: javascript php ajax redirect

如果我的php字符串是这样的。 $ ResponseG是我的字符串。

$responseG = $_SESSION['id']." | ";
$responseG .= $_SESSION['type']." | ";
$responseG .= $_SESSION['username']." | ";
$responseG .= $_SESSION['last_active']." | ";
$responseG .= $_SESSION['last_login']." | ";

这将是这样的。

2 |用户|用户名| time1 | TIME2

这是Ajax

if(RequestObject){
RequestObject.open("POST", "calls/checkLog.php");
RequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
RequestObject.onreadystatechange = function(){
if(RequestObject.readyState == 4 && RequestObject.status == 200){
if(RequestObject.readyState == 4){
if(RequestObject.responseText !== "Username or Password are Invalid!"){
if(RequestObject.responseText !== "Username and Password are Required to Continue."){
window.location.replace("http://folder/members.php");
}else{document.getElementById('alertLog').innerHTML = RequestObject.responseText;}
}else{document.getElementById('alertLog').innerHTML = RequestObject.responseText;}}}}
var dataStringA = document.getElementById('inputaID').value;
var dataStringB = document.getElementById('password').value;
var data = dataStringA+'|'+dataStringB+'|';
RequestObject.send("data=" + data);}
return false;}

在本节中,我想将字符串发送到重定向的URL 我如何将php字符串发送到members.php页面

window.location.replace("http://folder/members.php");

请不要jQuery。解决方案必须是本机Javascript。提前致谢。

1 个答案:

答案 0 :(得分:2)

这可以通过在URL的查询字符串中传递响应来完成:

window.location.replace("http://folder/members.php?userInfo=" + encodeURIComponent(RequestObject.responseText));

然后,您应该能够使用$_GET['userInfo']

访问members.php中传递的数据