fix parsing json response with charset

pull/43/merge
nightwing 2015-05-18 16:09:25 +04:00
rodzic d822cd5457
commit 69f1ae7f5a
1 zmienionych plików z 11 dodań i 14 usunięć

Wyświetl plik

@ -66,7 +66,7 @@ define(function(require, module, exports) {
return done(new Error("Could not serialize body as json")); return done(new Error("Could not serialize body as json"));
} }
} }
if (contentType.indexOf("application/x-www-form-urlencoded") === 0) { else if (contentType.indexOf("application/x-www-form-urlencoded") === 0) {
body = qs.stringify(body); body = qs.stringify(body);
} }
else if (["[object File]", "[object Blob]"].indexOf(Object.prototype.toString.call(body)) > -1) { else if (["[object File]", "[object Blob]"].indexOf(Object.prototype.toString.call(body)) > -1) {
@ -75,7 +75,7 @@ define(function(require, module, exports) {
} }
else { else {
body = body.toString(); body = body.toString();
} }
} }
var timer; var timer;
@ -105,18 +105,15 @@ define(function(require, module, exports) {
headers: parseHeaders(xhr.getAllResponseHeaders()) headers: parseHeaders(xhr.getAllResponseHeaders())
}; };
var data; var data = xhr.responseText;
switch (options.overrideMimeType || res.headers["content-type"]) { if ((options.overrideMimeType || res.headers["content-type"])
case "application/json": .indexOf("application/json") === 0
try { ) {
data = JSON.parse(xhr.responseText); try {
} catch (e) { data = JSON.parse(data);
return done(e); } catch (e) {
} return done(e);
break; }
default:
data = xhr.responseText;
} }
if (this.status > 299) { if (this.status > 299) {