Skip to content
Browse files
Just added support for Accept headers in Ajax requests - defaults to …
…the correct header depending on the type of request that's being performmed. (Bug #1986)
  • Loading branch information
jeresig committed Jan 14, 2008
1 parent c27cbdc commit 5974495e6b1f40076ef257bc886dacd0c2e27bd7
Showing 1 changed file with 14 additions and 1 deletion.
@@ -146,7 +146,15 @@ jQuery.extend({
async: true,
data: null,
username: null,
password: null
password: null,
accepts: {
xml: "application/xml, text/xml",
html: "text/html",
script: "text/javascript, application/javascript",
json: "application/json, text/javascript",
text: "text/plain",
default: "*/*"

// Last-Modified header cache for next request
@@ -275,6 +283,11 @@ jQuery.extend({

// Set header so the called script knows that it's an XMLHttpRequest
xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");

// Set the Accepts header for the server, depending on the dataType
xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
s.accepts[ s.dataType ] + ", */*" :

This comment has been minimized.

Copy link

bradgessler Mar 18, 2014

Is there context for why a */* mime type is appended to requests? This behavior is still present in the most recent builds of jQuery AJAX where very specific formats are specified in a jQuery request. For example, the request:


creates the header Accept:application/json, text/javascript, */*; q=0.01. I would expect for this header to be Accept:application/json, text/javascript since this type of jQuery request would fail on responses.

s.accepts.default );
} catch(e){}

// Allow custom headers/mimetypes

0 comments on commit 5974495

Please sign in to comment.