【发布时间】:2014-01-09 03:31:22
【问题描述】:
我有两台不同的服务器,每台都有自己的域。我正在从一台服务器到另一台服务器运行 ajax 脚本。我收到“No 'Access-Control-Allow-Origin'”错误,但我的服务器端脚本仍在处理请求。
我的服务器端脚本是否有原因处理 ajax 请求,即使它违反了 CORS?
更新:这是我的代码
var init,
yourname,
youremail,
friendname,
friendemail,
message,
url,
data,
request;
init = function() {
yourname = $('input[name=yourName]').val();
youremail = $('input[name=yourEmail]').val();
friendname = $('input[name=friendName]').val();
friendemail = $('input[name=friendEmail]').val();
message = $('textarea[name=comments]').val();
url = window.location.href;
data ='yourName=' + yourname + '&yourEmail=' + youremail + '&friendName=' + friendname + '&friendEmail=' + friendemail + '&comments=' + message + '&url=' + url;
request = $.ajax({
type: 'POST',
url: features.captureForm.processing,
data: data,
cache: false
});
request.done(function() {
$('#form').css({'height':'0','overflow':'hidden'});
$('#formHeader').find('h2').html('Thank you!');
setTimeout(function(){
HideShowForm.init();
$('#form').css({'height':'auto'});
$('#formHeader').find('h2').html('Send to a friend!');
},3000);
});
request.fail(function() {
console.log('Something went wrong');
});
};
【问题讨论】:
-
你能和我们分享你的代码吗?...
-
HTTP 服务器的类型会有所帮助。我的猜测,虽然可能是正在发送
OPTIONS请求,但是您的服务器配置为允许服务器端脚本响应这些请求,但是,您的服务器端脚本不知道不做任何正常的事情,因为它不是t 查看 HTTP 动词.... 类似的东西。
标签: javascript ajax cors