码迷,mamicode.com
首页 > Web开发 > 详细

Pass request headers in a jQuery AJAX GET call

时间:2021-01-04 10:46:12      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:xhr   localhost   flow   type   ons   keyword   script   att   javascrip   

Pass request headers in a jQuery AJAX GET call

回答1

As of jQuery 1.5, there is a headers hash you can pass in as follows:

$.ajax({
    url: "/test",
    headers: {"X-Test-Header": "test-value"}
});

From http://api.jquery.com/jQuery.ajax:

 

回答2

Use beforeSend:

$.ajax({
         url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
         data: { signature: authHeader },
         type: "GET",
         beforeSend: function(xhr){xhr.setRequestHeader(‘X-Test-Header‘, ‘test-value‘);},
         success: function() { alert(‘Success!‘ + authHeader); }
      });

http://api.jquery.com/jQuery.ajax/

http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method

 

Pass request headers in a jQuery AJAX GET call

标签:xhr   localhost   flow   type   ons   keyword   script   att   javascrip   

原文地址:https://www.cnblogs.com/chucklu/p/14211414.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!