简体   繁体   English

HTTP标头在$ .AJAX调用中不起作用

[英]HTTP headers not working in $.AJAX call

No matter which method I try for setting headers in AJAX call and no matter which header I set, every-time, if there is a header, my AJAX call is aborted, and call doesn't go through, and since I need to set Authorization header, if no header is there, call returns 401. 无论我尝试使用哪种方法来设置AJAX调用中的标头,无论我设置了哪个标头,每次,如果有标头,我的AJAX调用都将中止,并且调用不会进行,因为我需要设置授权标头,如果没有标头,则调用返回401。

 <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ var authorizationToken=1; $.ajax ({ type: "GET", url: "http://<someURL>?$format=json", beforeSend: function (request) { request.setRequestHeader("Authority", authorizationToken); }, success: function (){ alert('Thanks for your comment!'); }, error: function (a,b,c,d){ alert('Try again please'); } }); }); }); </script> </head> <body> <button>Send an HTTP GET request to a page and get the result back</button> </body> </html> 

If there is no header present, call is not aborted and 401 is returned. 如果不存在标题,则不会中止调用,并返回401。 Can you please tell me what is wrong in AJAX call? 您能告诉我AJAX通话有什么问题吗? Since this works in rest client with same server, i don't think its a server issue. 由于这在具有相同服务器的其余客户端中有效,因此我认为这不是服务器问题。

您是否要设置Authorization标头而不是Authority

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM