寻找有关故障排除方法的其他一些想法。我的联系页面上有一个google noCaptcha reCaptcha。
<div class="g-recaptcha" data-sitekey="my-site-key" data-callback="onReturnCallback" data-theme="light"></div>
在同一页面上,我有回调脚本
<script type="text/javascript">;
var onReturnCallback = function(response) {
console.log('callback');
var url = '../php/proxy.php?url=' + 'https://www.google.com/recaptcha/api/siteverify';
console.log(url);
var request = $.ajax({
'url': url,
data: {
response: response
},
dataType: 'json',
success: function(data) {
var res = data.success.toString();
if (res === 'true') {
document.getElementById('g-recaptcha').innerHTML = 'THE CAPTCHA WAS SUCCESSFULLY SOLVED';
document.getElementById('theButton').removeAttribute('disabled');
document.getElementById('theButton').innerHTML = 'Submit';
}
},
statusCode: {
404: function() {
alert("page not found");
}
}
}); //ajax done
request.done(function(msg) {
alert("ajax finished" + msg);
});
request.fail(function(jqXHR, textStatus) {
alert("Request failed: " + textStatus)
});
}; // end of onReturnCallback
</script>;
并在一个单独的文件中
<?php
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
header('HTTP/1.0 403 Forbidden');
die('You are not allowed to access this file.');
}
header('Content-type: application/json');
$url=$_GET['url'];
$response=$_GET['response'];
$secret = "my-secret-key";
$params = array('secret'=>$secret, 'response'=>$response);
$json=file_get_contents( $url . '?secret=' . $secret . '&response=' . $response);
echo $json;
?>
这一切都在我当地的MAMP设置上运行良好。当我将它转移到服务器时,我收到来自request.fail的警报,说有一个解析错误。 proxy.php的权限是755.我尝试删除
dataType: 'json'
来自请求的- 响应没有变化。不知道还需要什么来帮助。