php - issue updating html after ajax response received -
after having multiple issues requesting data server posted this question. never got code work ended rewriting whole ajax request , i'm able insert data in database.
however, issue i'm having responsetext being sent ajax request not updating html.
at end of registration script, after values have been inserted database, have code tests make sure registration email has been sent user , sends string ajax request:
if (mail($to, $subject, $message, $headers)) { echo "email_success"; exit; } else { echo "email_failure"; exit; }
once response has been received have condition test string has been returned:
hr.onreadystatechange = function() { if (hr.readystate == 4 && hr.status == 200) { if (hr.responsetext == "email_success") { window.scrollto(0,0); gebi("signupform").innerhtml = "<p>sign successful. check email activate account.</p>"; } else { gebi("status").innerhtml = hr.responsetext; gebi("signupbtn").style.display = "block"; } } }
the issue i'm have "signup_success"
string not being recognised true
, instead fires else statement.
what doing wrong?
probably error have trim response text before comparation.
trim code:
if (!string.prototype.trim) { string.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); }; }
and then
hr.onreadystatechange = function() { if (hr.readystate == 4 && hr.status == 200) { var responsetext = hr.responsetext.trim(); if (responsetext == "email_success") { window.scrollto(0,0); gebi("signupform").innerhtml = "<p>sign successful. check email activate account.</p>"; } else { gebi("status").innerhtml = hr.responsetext; gebi("signupbtn").style.display = "block"; } } }
Comments
Post a Comment