2013-03-11 183 views
2

jQuery 1.9.1jQuery ajax授权令牌标头失败

请求永远不会被发送,似乎只是出错。 console.log输出显示Request failed: error我不知道如何进一步调试。

$.ajax({ 
    beforeSend: function (xhr) { xhr.setRequestHeader ('Authorization', 'Token c576f0136149a2e2d9127b3901015545') }, 
    type: "GET", 
    url: "https://example.com/endpoint", 
    dataType: "json" 
}).done(function(msg) { 
    console.log(msg); 
}).fail(function(jqXHR, textStatus, errorThrown) { 
    console.log("Request failed: " + textStatus); 
    console.log(errorThrown); 
}); 

检查谷歌浏览器的网络流量显示

  • Method: OPTIONS
  • Status: (canceled)
  • Type: Pending

但是使用curl正常工作:

curl https://example.com/endpoint -H 'Authorization: Token token="c576f0136149a2e2d9127b3901015545"'

这里是的jsfiddle:http://jsfiddle.net/2vtyD/1/

注:这是不是Access-Control-Allow-Origin一个问题,因为我有这部分工作。

我知道我必须失去了一些东西......

更新:

一切正常,当我切换到http。只有在使用https时才会出现此问题。我认为这可能是因为我正在使用自签名证书(无效)。但其他SSL请求(非授权,即不是'OPTIONS')工作得很好。所以它似乎只是SSL和OPTIONS请求的组合。 chrome中的状态表示取消,从查看服务器日志apache日志显示一些活动,但它永远不会成为rails web应用程序。

下面是Apache日志的sniplet:

[info] [client 10.0.2.2] (70007)The timeout specified has expired: SSL input filter read failed. 
[info] [client 10.0.2.2] Connection closed to child 10 with standard shutdown (server example.com:443) 
[info] [client 10.0.2.2] Connection to child 11 established (server example.com:443) 
[info] Seeding PRNG with 656 bytes of entropy 
[info] [client 10.0.2.2] (70014)End of file found: SSL input filter read failed. 
[info] [client 10.0.2.2] Connection closed to child 11 with standard shutdown (server example.com:443) 

然而,这些类型的消息正在发生的所有SSL请求。所以我基本上对如何继续下去感到茫然。

回答

1

使用有效的SSL证书。

由于某些原因,GET,POST,PUT和DELETE请求可以正常使用自签名证书。但是OPTIONS请求没有。使用有效的SSL证书,一切都会正常工作。