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

前端 未结 9 1133
独厮守ぢ
独厮守ぢ 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 03:59

    Assuming JQuery ajax, you can add custom headers like -

    $.ajax({
      url: url,
      beforeSend: function(xhr) {
        xhr.setRequestHeader("custom_header", "value");
      },
      success: function(data) {
      }
    });
    

提交回复
热议问题