Search code examples
javascriptjqueryheaderjquery-ajax

Not able to pass 'date' header in ajax jquery request


We are not able to see in the request headers. Does not seem like a server issue. It is mostly from the client side/browser.

$(document).ready(function(e) {
       
    $.ajax({
        url: form_url, 
        type: form_method,      
        data: form_data,     
        cache: false,
        headers: {'date': (new Date()).toUTCString()},
        success: function(returnhtml){
            $("#result").html(returnhtml); 
            $("#loadingimg").hide();                    
        }           
    });    
    
});

Request headers

http://jsfiddle.net/ddtxra/60wme3pf/

Is it a bug ?


Solution

  • This is explained here as:

    Date is listed in the forbidden header names in the fetch spec - so this code will not send Date header

    Where the fetch spec lists reserved names:

    A forbidden header name is a header name that is a byte-case-insensitive match for one of

    Accept-Charset
    Accept-Encoding
    Access-Control-Request-Headers
    Access-Control-Request-Method
    Connection
    Content-Length
    Cookie
    Cookie2
    Date
    DNT
    Expect
    Host
    Keep-Alive
    Origin
    Referer [sic]
    TE
    Trailer
    Transfer-Encoding
    Upgrade
    Via

    Use a different header name, but not one of the other reserved header names and your fiddle (with your code added) works fine: http://jsfiddle.net/19yjdft5/