Pass request headers in a jQuery AJAX GET call

2021-01-04 23:29

阅读:744

标签: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


评论


亲,登录后才可以留言!