How can I add a custom HTTP header to ajax request

2018-12-31 06:20发布

Does anyone know how to add or create a custom HTTP header using JavaScript or jQuery?

8条回答
路过你的时光
2楼-- · 2018-12-31 07:11

"setRequestHeader" method of XMLHttpRequest object should be used

http://help.dottoro.com/ljhcrlbv.php

查看更多
像晚风撩人
3楼-- · 2018-12-31 07:12

Or, if you want to send the custom header for every future request, then you could use the following:

$.ajaxSetup({
    headers: { "CustomHeader": "myValue" }
});

This way every future ajax request will contain the custom header, unless explicitly overridden by the options of the request. You can find more info on ajaxSetup here

查看更多
登录 后发表回答