i have a problem when posting a captcha to validate by php.
I send the captcha_value string to the captcha_check.php and I don't know how to retrieve the returned value 'true' or 'false'
$("#myForm").submit(function() {
$.ajax({
type: "POST",
url: '/captcha_check.php',
data: captcha_value
success: function(data) {
**?WHAT TO DO HERE? how to get true or false**
}
});
captcha_check.php
if ($_POST['captcha'] == $_SESSION['captcha'])
echo 'true';
else
echo 'false';
?>
解决方案
I set header to output as xml.
captcha_check.php
header('Content-Type:text/xml');//needed to output as xml(that is my choice)
echo "";
if ($_POST['captcha'] == $_SESSION['captcha'])
echo 'true';
else
echo 'false';
echo "";
?>
$("#myForm").submit(function() {
$.ajax({
type: "POST",
url: '/captcha_check.php',
dataType:'xml',
data: captcha_value
success: function(data) {
if($(data).find('message').text() == "true"){
//now you get the true. do whatever you want. even call a function
}
else{
//and false
}
}
});
this is my solution probably works for you also. I always prefer xml for communication. Thats my choice.