Skip to content
Permalink
Browse files

Added json to auto-detected dataTypes

Signed-off-by: jaubourg <aubourg.julian@gmail.com>
  • Loading branch information
jaubourg
jaubourg committed Dec 22, 2009
1 parent dfa28ea commit 4911a142bc85b056712cc1c0412bdc9752af292a
Showing with 16 additions and 9 deletions.
  1. +16 −9 src/transports/xhr.js
@@ -81,24 +81,31 @@ jQuery.ajax.bindTransport(function(s) {
responseHeaders = xhr.getAllResponseHeaders();

// Guess response if needed & update datatype accordingly
var transportDataType = s.dataTypes[0],
var dataTypes = s.dataTypes,
transportDataType = dataTypes[0],
xml = xhr.responseXML,
text = xhr.responseText;

if ( transportDataType == "auto" ) { // Auto (xml or text determined given headers)
if ( transportDataType == "auto" ) { // Auto (xml, json or text determined given headers)

var ct = xhr.getResponseHeader("content-type"),
isXML = ct && ct.indexOf("xml") >= 0;
var isDataType = dataTypes.length == 1,
ct = xhr.getResponseHeader("content-type"),
isXML = ct && ct.indexOf("xml") >= 0,
isJSON = !isXML && ct && ct.indexOf("json") >= 0;

response = isXML ? xml : text;
s.dataTypes[0] = isXML ? "xml" : "text";

if ( s.dataTypes.length == 1 ) {
s.dataType = s.dataTypes[0];

dataTypes[0] = isXML ? "xml" : ( isJSON ? "json" : "text" );

if ( isJSON ) {
dataTypes.unshift("text");
}

if ( isDataType ) {
s.dataType = dataTypes[ isJSON ? 1 : 0 ];
}


} else if ( transportDataType != "xml" || ! xml ) { // Text asked OR xml not parsed

response = text;

0 comments on commit 4911a14

Please sign in to comment.
You can’t perform that action at this time.