this works:
$.ajax({
type: 'POST',
url: 'register.php',
data: {captcha: captcha
},
success: function() {
$('#loading').hide();
$('#success').fadeIn();
}
error: function() {
$('#loading').hide();
$('#captcha').fadeIn();
$('#catErrorB').fadeIn();
}
});
sends captcha response to PHP and if entered correctly, you can register. problem is, is that if you incorectly enter your captcha, the JQuery still runs the functions for a successful run although the PHP ran a “die” and did nothing.
In PHP, if the captcha is entered incorrectly is does this
if (!$resp->is_valid) {
die ("false");
}
else
{
register
}
How do I request the error that PHP spits out so I can do something like?
success: function(find error) {
if(error == "false")
{
$('#loading').hide();
$('#captcha').fadeIn();
$('#catErrorB').fadeIn();
}
else
{
$('#loading').hide();
$('#success').fadeIn();
}
}
EDIT!:
With your help heres what it looks like now and it works fantastic!!
$.ajax({
type: 'POST',
url: 'register.php',
dataType: "json",
data: {
challenge: challenge,
response: response,
zip: zip
},
success: function(result) {
if (!result.success) {
$('#loading').hide();
$('#captcha').fadeIn();
$('#catErrorB').fadeIn();
}
else {
$('#loading').hide();
$('#success').fadeIn();
}
}
});
and the PHP
if (!$resp->is_valid) {
$response = array(success => false);
echo json_encode($response);
}
else
{
$response = array(success => true);
echo json_encode($response);
Ya’ll are the coolest. My first JQuery I’ve ever done, It’s came out so awesome. This site rules!
PHP:
jQuery: