Jquery CORS飞行前不返回

Jquery CORS飞行前不返回,jquery,iis-7.5,cors,Jquery,Iis 7.5,Cors,我正在努力实现CORS,这样我的Ember应用程序就可以与另一台服务器上的API通信。我需要发送两个请求:通过POST的身份验证请求,然后向其中一个API端点发送GET请求 这两个请求都会启动飞行前请求。验证飞行前请求运行正常。然后,当我运行对API的请求时,飞行前请求挂起。Chrome将状态和类型显示为“待定”,请求永远不会完成 这是身份验证代码。我在这里使用jQuery1.10.2 $.ajax({ type: 'POST', url: 'https://blahblah

我正在努力实现CORS,这样我的Ember应用程序就可以与另一台服务器上的API通信。我需要发送两个请求:通过POST的身份验证请求,然后向其中一个API端点发送GET请求

这两个请求都会启动飞行前请求。验证飞行前请求运行正常。然后,当我运行对API的请求时,飞行前请求挂起。Chrome将状态和类型显示为“待定”,请求永远不会完成

这是身份验证代码。我在这里使用jQuery1.10.2

  $.ajax({
    type: 'POST',
    url: 'https://blahblahblah.edu/AstraDev/Logon.ashx',
    data: "{username: '', password: ''}",
    contentType: 'text/json',

    xhrFields: {
      withCredentials: false 
    },

    headers: {
    },

    success: function(response) {
      console.log(response);
    },

    error: function(response) {
      console.log(response);
    }
  });
与API GET请求的代码非常相似

  $.ajax({
    type: 'GET',
    url: 'https://blahblahblah.edu/AstraDev/~api/query/room',
    data: {fields: "Id"},
    contentType: 'application/json; charset=utf-8',
    xhrFields: {
      withCredentials: true 
    },
    headers: {
    },
    success: function(response) {
      console.log(response)
    },
    error: function(response) {
      console.log(response)
    }
  });
如果我将GET的内容类型更改为不预飞行的内容类型(如“text/plain”),请求将失败。但是,如果我做了任何预飞行的事情,预飞行就会挂起

下面是相关的服务器配置。我正在使用iis7.5

<httpProtocol>
     <customHeaders>
       <add name="Access-Control-Allow-Origin" value="http://localhost:8888" />
       <add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
       <add name="Access-Control-Allow-Headers" value="Content-Type" />
       <add name="Access-Control-Allow-Credentials" value="true" />
    </customHeaders>
</httpProtocol>


CORS对我来说是个新概念。也许我遗漏了一些明显的东西。有什么想法吗?谢谢。

没有看到响应标题可能有很多原因。但这是我在处理飞行前问题时发现的。下面是一个在飞行前检查后处理json主体的JavaScript示例。初始xhr.open会与teamviewer服务器进行飞行前检查。您只发送满足飞行前要求的最小请求头。飞行前经过时发送json主体get

函数createsession(groupid,meetwith){
var xhr=new XMLHttpRequest();
var url='1〕https://webapi.teamviewer.com/api/v1/sessions';
var jbody=JSON.stringify({“groupid”:groupid,
“说明”:“全球经理干预”,
“最终客户”:{“名称”:“+meetwith+”}
});
callTVAPI();
函数callTVAPI(){
if(xhr){
xhr.open('POST',url,true);
setRequestHeader('Content-Type','application/json');
xhr.setRequestHeader('Authorization','bearrier@(ViewBag.TeamViewerToken');
xhr.onreadystatechange=函数(){
if(xhr.readyState!==XMLHttpRequest.DONE){
返回;
}
如果(xhr.status!==200){
返回;
}
var data=jQuery.parseJSON(xhr.response);
alertify.success(“启动:“+data.supporter\u链接”);
};
xhr.send(jbody);
}
}

}
因此,服务器可能根本无法正确处理选项请求。您是否验证了服务器在接收到此类请求时所做的操作?