[英]recpatcha returns 200, still get error with jQuery ajax
All of my other searches yield responses about cross-domain requests. 我所有其他搜索都产生有关跨域请求的响应。 It appears that I'm not having a problem with that. 看来我没有问题。 I'm getting a response from the recaptcha server, but it's not being interpreted correctly. 我收到来自Recaptcha服务器的响应,但未正确解释。
<script>
function verifyCaptcha() {
jQuery.ajax({
method: "POST" ,
url: "https://www.google.com/recaptcha/api/siteverify",
data: { secret: "xxxxxxxxxxxxxxxxxxx" , response: "<% $recaptcha_response %>" },
dataType: 'jsonp' ,
success: function( result ) {
alert( result.success ) ;
},
error: function( xhr ) {
alert('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' Response Text: ' + xhr.responseText);
}
})
}
onload=verifyCaptcha ;
</script>
This function lives in a page that's the target of a submitted form. 此函数位于提交表单的目标页面中。 When I check fireBug for the results, I get this in my alert message: 当我检查fireBug的结果时,我在警报消息中得到了这个:
Request Status: 200 Status Text: success Response Text: undefined
And the response captured by FireBug is FireBug捕获的响应是
{
"success": true
}
It seems that it gets mad without the parens wrapped around the returned JSON which I thought were supposed to come free with dataType: 'jsonp'
似乎很生气,没有将括号包裹在返回的JSON上,我认为应该将其与dataType: 'jsonp'
一起释放
How do I resolve the success of this? 我该如何解决这个问题?
UPDATE UPDATE
Adding additional return parameters to the error funcion: ( xhr , message , errorThrown )
produced the following: 在错误函数中添加其他返回参数: ( xhr , message , errorThrown )
产生了以下结果:
Request Status: 200
Status Text: success
Response Text: undefined
Message: parsererror
ErrorThrown: Error: jQuery1120043068059910713263_1455115913634 was not called
I'm guessing that the jQuery1120043068059910713263_1455115913634 was not called
message is the callback function randomly named by jQuery. 我猜测jQuery1120043068059910713263_1455115913634 was not called
message是jQuery随机命名的回调函数。 Does this mean that I need to add something to my logic, or that the reCaptcha server does not indeed support jsonp ? 这是否意味着我需要在逻辑中添加一些内容,或者reCaptcha服务器确实不支持jsonp?
Setting the dataType
to "json"
gives me a request status of 0. 将dataType
设置为"json"
会使我的请求状态为0。
UPDATE 2 更新2
I added this to my function: 我将此添加到我的功能:
jsonp: false,
jsonpCallback: 'onJSONPLoad',
and my errorThrown
text changed to: Error: onJSONPLoad was not called
which leads me to conclude that reCaptcha does not support jsonp
. 并且我的errorThrown
文本更改为: Error: onJSONPLoad was not called
这使我得出结论,说reCaptcha不支持jsonp
。 Can anyone confirm this? 有人可以确认吗?
I guess the Answer is: 我猜答案是:
The POST method is not available for jsonp, only GET POST方法不适用于jsonp,仅适用于GET
update: 更新:
As well as in the comment stated setting the dataType to "json"
and it will automatically converted to jsonp, maybe try that 以及在注释中所述,将dataType设置为"json"
,它将自动转换为jsonp,也许尝试
also you can add a third argument to the error function 您也可以在错误函数中添加第三个参数
error: function( xhr, message, errorThrown ) {
and errorThrown maybe is more explicit 和errorThrown可能更明确
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.