我正在尝试使用jQuery在AJAX GET中传递请求标头。在下面的块中,“数据”自动传递查询字符串中的值。有没有办法在请求标头中传递该数据?
$.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); } });
用途beforeSend:
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