我了解使用 ajax 尝试从另一个网站获取信息时的跨域错误,但根据 jQuery,您应该能够改用 jsonp 请求。在尝试显示 recaptcha 时,我很难做到这一点。问题是我无法使用插件来实现这一点,这会使它变得容易得多。
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script type="text/javascript">
function showRecaptcha() {
Recaptcha.create("// removed for example", 'captchadiv', {
tabindex: 1,
theme: "red",
callback: Recaptcha.focus_response_field
});
}
jQuery(document).ready(function(){
showRecaptcha('recaptcha_div');
jQuery('#contact-form').submit(function(){
var challenge = Recaptcha.get_challenge();
var response = Recaptcha.get_response();
var ip = "<?php print $_SERVER['REMOTE_ADDR'] ?>";
var private = "// removed for example";
var requestUrl = "http://www.google.com/recaptcha/api/verify?privatekey=" + private + "&remoteip=" + ip + "&challenge=" + challenge + "&response=" + response;
jQuery.getJSON(requestUrl, function(json) {
alert("what");
});
})
});
</script>
<form id="">
// Form stuff
</form>
<div id="captchadiv"></div>
<input type="submit" name="submit" id="form-submit">
我应该如何将其调用到谷歌服务器并获得正确的回调。它基本上会返回一个真或假。我要么得到臭名昭著的 Access-Control-Allow-Login,要么得到关于纯文本的错误。有人有建议吗?