javascript - ajax responseText is returning header bar with echo content -
i using ajax
communicate php
.when fetched data shows typed email present on database,i used echo
message 'email taken,try email'.but ajax responsetext
returning header file , echoed content
.here image
how can echoed message ajax responsetext?
here codes
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 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 not met @ 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 creating account.a welcome email has been sent email.<br/><br/>go <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 user_det 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 registered.please use email"; echo $abul; exit(); } else{ $sql11x="insert 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"; }
i appreciate help.
thanks time.
with additional comment, see what's happening.
it not visible partial php code posted, , should post whole code if not heavy.
but it's pretty sure error resides somewhere near top of php file: when test if(isset($_post['f'])){
have output begin of original page, generated same php file.
btw, should ensure exit;
after echoing message responding ajax call.
Comments
Post a Comment