简体   繁体   English

recpatcha返回200,但仍然与jQuery ajax错误

[英]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.

相关问题 Ajax 删除请求返回 200 但触发错误 - Ajax delete request returns 200 but fires error 对Struts2动作类的jQuery Ajax请求总是返回200 ok,但是会触发error事件 - jQuery Ajax request to Struts2 action class always returns 200 ok, but error event is fired jQuery AJAX GET请求始终返回错误 - JQuery AJAX GET request always returns error jQuery $ .ajax使用JSONP调用跨域,返回状态200,但是错误函数被调用而不是成功 - jQuery $.ajax call for cross domain with JSONP, returns status 200, but error function is being called instead of success jQuery ajax Web服务304和200错误() - jquery ajax webservice 304 and 200 Error () jquery ajax在直接执行时返回成功,但在附加到按钮时返回错误,即使服务器响应为200 OK - jquery ajax returns success when directly executed, but returns error when attached to button, even though server response is 200 OK jQuery Ajax Request 200但状态错误 - jQuery Ajax Request 200 but status error 使用 Ajax 和 jQuery 检查文件是否存在 - 始终返回 200 响应 - Using Ajax and jQuery to check if file exists - always returns 200 response ReactJS Ajax调用返回200和结果,但错误:无法获取 - ReactJS Ajax call returns with 200 and results but Error: Failed to fetch Ajax请求仅返回错误,但状态码为200 OK - Ajax Request Only Returns Error But The Status Code Is 200 OK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM