SetRequestHeader not working in jQuery.ajax ()

Using jQuery ajax () call below does not work. If I remove the parameter beforeSend, it works fine. According to Chrome’s web inspector, his status when it’s not working is “Unload”. Tested with jQuery 1.7.2 and 1.9.1 and Chrome, Safari and Firefox. It does not work no matter what parameters I put in setRequestHeader(for example, "test", "true" also does not work). When I turn beforeSendin the request headers include the following: Access-Control-Request-Headers:accept, cache-control, origin. If it matters, it api_url’s in a different subdomain, but we installed CORS on the server so that it works fine in all other cases. I need to set the Cache-Control header to remove it before Send is not an option.

$.ajax({
    url: api_url, 
    beforeSend : function (xhr){xhr.setRequestHeader('Cache-Control', "public");} , 
    dataType: "json", 
    success: successCallback, 
    error: APIError 
});

: it seems to reach the node.js server since it responds as a status of 200. Is it possible that the server is responding to the header? Again, it does this no matter what key / value parameters I use, so it will not be related to caching.

update2: in my console, I get a "Request Header Field". Cache-Control is not allowed Access-Control-Allow-Headers. "I tried Google, but no closer to the answer. It seems that no request header field is accepted. Does this mean that node.js needs to be configured to accept the header?

+5
source share

All Articles