Access Control Request Headers, is added to header in AJAX request with jQuery

前端 未结 6 1409
不知归路
不知归路 2020-11-22 10:29

I would like to add a custom header to an AJAX POST request from jQuery.

I have tried this:

$.ajax({
    type: \'POST\',
    url: url,
    headers:          


        
6条回答
  •  日久生厌
    2020-11-22 11:02

    Here is an example how to set a request header in a jQuery Ajax call:

    $.ajax({
      type: "POST",
      beforeSend: function(request) {
        request.setRequestHeader("Authority", authorizationToken);
      },
      url: "entities",
      data: "json=" + escape(JSON.stringify(createRequestObject)),
      processData: false,
      success: function(msg) {
        $("#results").append("The result =" + StringifyPretty(msg));
      }
    });
    

提交回复
热议问题