【发布时间】:2013-06-23 11:53:00
【问题描述】:
我在同一台服务器上有两个独立的应用程序,其中一个 EmberJS 尝试对我的后端 API 进行跨域调用。
我设置了我的后端 API 以允许来自该特定来源的跨域请求。然而,有没有办法避免在这样的设置中使用 JSONP? $.ajax 在跨域请求被发送之前阻止它们。如果不是,CORS 的意义何在,我实现了哪个服务器端来接受来自我的 JS 前端源的请求?
编辑
AJAX 请求:
$.ajax({
url: "api.lvh.me:3000/accounts/login",
data: cred,
type: "POST",
xhrFields: {
withCredentials: true
},
success: function(response){
alert('succeeded!');
console.log(response);
alert(response);
},
failure: function(message){
alert("failed");
console.log(message);
alert(message);
}
});
【问题讨论】:
-
你为什么不简单地反向代理后端,这样CORS问题就不会发生?编辑:我不认为 $.ajax 会阻止这些请求,因为它必须询问服务器是否允许它们......
-
反向代理不允许所有跨域请求吗?
-
您是否尝试在 $.ajax 调用中将“http://”添加到 url 属性?
标签: javascript ruby-on-rails ajax ember.js cross-domain