我正在尝试使用jQuery的ajax功能访问reddit API。从我在网上看到的情况来看,我使用的代码应该能够执行CORS:
$.ajax({
type:"POST",
url:"http://reddit.com/api/login",
data: {
api_type:"json",
passwd:"MyRedditPassword",
rem:false,
user:"MyRedditUsername"
},
dataType:"text",
success:function(data){console.log("success:",data);},
error:function(error){console.log("error:",error);},
crossDomain:true,
xhrFields:{withCredentials:true}
});
这是访问
this part of reddit's API
.
我得到了错误
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
据我了解,这个错误是服务器端的问题;他们对我请求的响应没有CORS所需的报头。这意味着reddit的API不支持CORS。
However, the reddit admins said here that they have implemented CORS support
.
我的请求有什么问题,以至于我试图使用他们表示支持的功能,但我得到的答复是他们不支持?我需要在我的请求中做一些不同的事情来让reddit发送回CORS头吗?