jquery - 在 jQuery AJAX GET 调用中传递请求 header

标签 jquery ajax client-side

我正在尝试使用 jQuery 在 AJAX GET 中传递请求 header 。在接下来的 block 中,“数据”自动传递查询字符串中的值。有没有一种方法可以改为在请求 header 中传递该数据?

$.ajax({
         url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
         data: { signature: authHeader },
         type: "GET",
         success: function() { alert('Success!' + authHeader); }
      });

下面的也不行

$.ajax({
         url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
         beforeSend: { signature: authHeader },
         async: false,                    
         type: "GET",
                    success: function() { alert('Success!' + authHeader); }
      });

最佳答案

从 jQuery 1.5 开始,有一个 headers 哈希,您可以按如下方式传入:

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

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

headers (added 1.5): A map of additional header key/value pairs to send along with the request. This setting is set before the beforeSend function is called; therefore, any values in the headers setting can be overwritten from within the beforeSend function.

关于jquery - 在 jQuery AJAX GET 调用中传递请求 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3258645/

相关文章:

javascript - 使按钮响应 Enter 键

jquery - 在灯箱弹出窗口中添加内容并设置大小

javascript - 在 DOM 中存储数据的正确方法是什么

java - Olingo v2 - 如何编写带有导航实体的实体

javascript - 密码验证后发送数据

php - 使用AJAX根据下拉框返回查询结果

php - 在 Codeigniter 中显示基于先前下拉列表的第二个下拉列表

javascript - 调用ajax函数显示错误tUncaught TypeError : $ is not a function using jquery

javascript - 使用 jquery 创建透视对象

Android:使用 Parse 时使用服务器端