I'm trying to process captcha in form validation using google's reCaptcha. Basically, my validation function is called using onSubmit in the form tag, and then calls a second function to work with the recaptcha api.
Here's the code:
var returnValue;
var myData = {
privatekey : "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
remoteip : ip,
challenge : challenge,
response : response
};
$.ajax({
url: "http://www.google.com/recaptcha/api/verify",
type: "POST",
data: JSON.stringify(myData),
dataType: "text",
success: function(data) {
var result = data.split("\n");
if (result[0] == "true") {
returnValue = true;
}
else {
returnValue = false;
}
},
error: function(jqXHR, textStatus, errorThrown) {
alert("There was an error submitting the captcha. Please contact an administrator. \n\nError:\n" + textStatus, errorThrown);
returnValue = false;
},
complete: function(jqXHR, textStatus) {
return returnValue;
}
});
Using LiveHTTPHeaders in firefox, I can see the request go out to the service, and it looks like everything is being sent correctly. I get an HTTP/1.1 200 OK response back, and yet every single time the code goes to the error function. When the error function runs, jqXHR is:
Object { readyState=0, status=0, statusText="error"}
textStatus is "error", and errorThrown is ""
I've tried doing this a number of ways, including $.POST, and using .done(), .fail(), .always(), and it always behaves the same.
I've seen some other postings here having to do with problems with cross-domain requests, but none of those situations really seem to be relevant, because I actually am doing a cross-domain request, and those seemed to be issues where they were making requests to a file on the same domain, and it was being handled incorrectly as a cross-domain request.
I'm at my wits end here.. any help would be greatly appreciated.