How can I add a custom HTTP header to ajax request with js or jQuery?

前端 未结 9 1117
独厮守ぢ
独厮守ぢ 2020-11-22 03:17

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

9条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:04

    Assuming that you mean "When using ajax" and "An HTTP Request header", then use the headers property in the object you pass to ajax()

    headers(added 1.5)

    Default: {}

    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.

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

提交回复
热议问题