Permalink
Browse files

Parse JSON if the response header says so.

  • Loading branch information...
1 parent bf05701 commit a34d393e0e62f3f6a15f1495df1680b984805da4 @mcav mcav committed Dec 6, 2011
Showing with 8 additions and 1 deletion.
  1. +8 −1 packages/util/ajax.js
View
@@ -152,7 +152,14 @@ function onReadyStateChange(request, xhr) {
// .status will be 0 when requests are filled via app cache on at least iOS 4.x
if (xhr.status != 200 && xhr.status != 0) {
- cb({status: xhr.status, response: xhr.response}, null);
+ var response = xhr.response;
+ if (xhr.getResponseHeader('Content-Type') == 'application/json') {
+ try {
+ response = JSON.parse(response);
+ } catch(e) {
+ }
+ }
+ cb({status: xhr.status, response: response}, null);
} else {
var data = xhr.responseText;
if (request.type == 'json') {

0 comments on commit a34d393

Please sign in to comment.