2
我正在嘗試實施一個recaptcha。 我用jquery(ajax)調用驗證腳本(http://www.google.com/recaptcha/api/verify)。 這將數據類型限制爲JSONP,Google會拒絕所有其他數據類型。recaptcha:與驗證的難度
的問題是,谷歌的驗證,像這樣返回字符串: 真正 成功
或 假 「錯誤消息」
這導致瞭解析錯誤了jQuery側... 有沒有人有任何想法如何解決這個或最壞的情況下,即使有解析錯誤檢索responsetext?
以下是我的ajax請求。我添加了測試的完整和錯誤函數。
$("#verifyCaptcha").click(function(){
var chal = Recaptcha.get_challenge();
var resp = Recaptcha.get_response();
$.ajax({
url: "http://www.google.com/recaptcha/api/verify",
type: "GET",
data: {
privatekey: "MyKey",
remoteip: "172.29.129.133",
challenge: chal,
response: resp
},
//dataType: 'jsonp',
success: function(output){
output = output.split('/n');
console.log(output[0] + '**' + output[1]);
if(output[0].toLowerCase() == 'true')
$("#recaptcha_result").html('Succes: form will be sent.');
else
$("#recaptcha_result").html('Failed: form will NOT be sent.');
},
complete:function (xhr, status) {
if (status === 'error' || !xhr.responseText)
console.log('an error occured');
else
var data = xhr.responseText;
},
error: function(request, status, error)
{
if(request.responseText == 'success')
$("#recaptcha_result").html('Succes: form will be sent.');
else
$("#recaptcha_result").html('Failed: form will NOT be sent.');
console.log(request.responseText + '**'+status + "**"+error);
}
});
});