Search code examples
jqueryhttp-headersgetjson

What is the q=0.01 $.getJSON adds to the request header?


I've noticed this parameter on the Accept request header as:

Accept: application/json, text/javascript, */*; q=0.01

I am a bit curious about what the q=0.01 means?


Solution

  • The q attribute of the Accept header tells the web server which type of content the client prefers to receive in the event that the server can satisfy the request with multiple types of content. The exact value does not matter, only the relative values between multiple Accept headers.

    As long as there is only one Accept header, q does not actually do anything. However, if there are more than one it serves to specify priority. For example (taken from here), assume you have the headers:

    Accept:  *.*, q=0.1
    Accept:  audio/*, q=0.2
    Accept:  audio/basic q=1
    

    This may be interpreted as "if you have basic audio, send it; otherwise send me some other audio, or failing that, just give me what you've got."

    Of course noone actually forces the server to treat these headers as described (or even pay any attention to them for that matter).