gpt4 book ai didi

javascript - ajax responseText 返回带有回显内容的标题栏

转载 作者:行者123 更新时间:2023-11-28 07:18:11 24 4
gpt4 key购买 nike

我正在使用ajaxPHP进行通信。当获取的数据显示数据库中存在键入的电子邮件时,我将echo与消息一起使用“电子邮件已被占用,请尝试另一封电子邮件”。但是ajax responseText正在返回 header 文件和回显内容。这是一个图像

enter image description here

如何才能将回显消息作为 ajax responseText 获取?

这是我的代码

Javascript

function signup(){
var f=document.getElementById("firstname").value;
var l=document.getElementById("lastname").value;
var p=document.getElementById("password1").value;
var p2=document.getElementById("password2").value;
var e=document.getElementById("email").value;
var status=document.getElementById("status");

if(f=="" || l=="" || p=="" || p2=="" || e==""){
status.innerHTML="All fields are required";
}
else if(p!=p2){
status.innerHTML="passwords didn't match";
}
else{
document.getElementById("submitX").style.display = "none";
//status.innerHTML = 'please wait ...';
var x=new XMLHttpRequest();
x.open("POST","signup.php",true);
x.setRequestHeader("content-type","application/x-www-form-urlencoded");
x.onreadystatechange=function(){
if(x.readyState == 4 && x.status == 200){
if(x.responseText != "success"){ //this condition is not met at any circumstances
document.getElementById("submitX").style.display = "block";
status.innerHTML="";
//alert(x.responseText);
status.innerHTML = x.responseText;
}
else{
window.scrollTo(0,0);
status.innerHTML ="";
document.getElementById("diff_for").innerHTML = "";
document.getElementById("form1").innerHTML = "";
document.getElementById("form1").innerHTML = "Thank you for creating an account.A Welcome email has been sent to your email.<br/><br/>Go to <a href='login.php'>Login</a>";

}

}
}
x.send("F="+f+"&L="+l+"&E="+e+"&P="+p+"&P2="+p2);
}
}

PHP

if(isset($_POST['F'])){
$firstname=$_POST['F'];
$lastname=$_POST['L'];
$password=$_POST['P'];
$passmatch=$_POST['P2'];
$pass=md5($password);
$email=$_POST['E'];

$sqlx1="SELECT id FROM user_det WHERE email=? LIMIT 1";

mysqli_stmt_prepare($stmt30, $sqlx1);
mysqli_stmt_bind_param($stmt30, "s", $email);
mysqli_stmt_execute($stmt30);
mysqli_stmt_store_result($stmt30);
mysqli_stmt_bind_result($stmt30, $idx1);
$num_row1x=mysqli_stmt_num_rows($stmt30);

if($num_row1x>0){
//ob_end_clean();
//ob_start();
$abul="<br>This email is already registered.Please use another email";
echo $abul;
exit();
}
else{
$sql11x="INSERT INTO user_det(first_name,last_name,password,email,signup_date)
VALUES(?,?,?,?,now())";

mysqli_stmt_prepare($stmt30, $sql11x);
mysqli_stmt_bind_param($stmt30, "ssss", $firstname, $lastname, $pass, $email);
mysqli_stmt_execute($stmt30);

echo "success";
}

我非常感谢您的帮助。

感谢您的宝贵时间。

最佳答案

有了您的补充评论,现在我明白发生了什么。

仅您发布的部分 PHP 代码是不可见的,如果不是太重,您应该发布整个代码。

但可以肯定的是,您的错误位于 PHP 文件顶部附近的某个位置:当您测试 if(isset($_POST['F'])){ 时,您已经输出了 begin原始页面的内容,由同一个 PHP 文件生成。

顺便说一句,您还应该确保在响应 Ajax 调用的回显消息后exit;

关于javascript - ajax responseText 返回带有回显内容的标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30609211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com