【发布时间】:2014-05-28 21:08:11
【问题描述】:
我正在尝试使用带有以下代码 sn-p 的方法 post 进行 JQUERY ajax 调用, 但是调用没有对服务器进行并且接收错误..请求的资源上没有“Access-Control-Allow-Origin”标头。
根据我从各种帖子中看到的建议,我们在服务器端代码中添加了这些标头。那里没有运气。 我也在客户端添加了标题。 我正在尝试从本地机器到开发环境中的服务器。 另一个 get 请求工作正常,我只有 post 有问题。 我尝试了 JSON.stringify 的数据,但没有运气。
$.ajax({
url: ttsCreateURL,
type: "POST",
dataType: 'json',
crossDomain: true,
data: { "ballotId" : "0" ,"conMonth": "JUN2014","empId":"9999","airlineCode":"AA", "createdDate":"" },
success: function(response){
alert(response);
},
error:function(xhr, ajaxOptions, thrownError){
//ajaxError("There was an error . Please try again.",xhr, ajaxOptions, thrownError);
$('#Main').load('error.html');
}
});
当我尝试在浏览器中查看 url 以及查询字符串参数时,我看到错误 415:不支持的媒体类型 错误。
【问题讨论】:
-
您的服务器是否支持 JSON 的“接受”标头?
-
你真的得到了 cors 标题吗?检查 curl -I 网址。如果没有,您应该在服务器(@ttsCreateURL)上正确启用它enable-cors.org/server.html