Skip to content

Instantly share code, notes, and snippets.

@orient-man
Created September 30, 2013 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orient-man/cc14924bb31ec46462b5 to your computer and use it in GitHub Desktop.
Save orient-man/cc14924bb31ec46462b5 to your computer and use it in GitHub Desktop.
Temporary hack to set Content-Type response header for JSON
@@ -157,6 +157,10 @@
} else {
this.responseXML = mockHandler.responseXML;
}
+ } else if (typeof mockHandler.responseText == 'object') {
+ // since 1.9 responseText type has to match contentType
+ mockHandler.contentType = 'application/json';
+ this.responseText = JSON.stringify(mockHandler.responseText);
} else {
this.responseText = mockHandler.responseText;
}
@@ -250,8 +254,12 @@
return mockHandler.contentType || 'text/plain';
}
},
- getAllResponseHeaders: function() {
- var headers = '';
+ getAllResponseHeaders: function () {
+ var headers = '';
+ // since 1.9 responseText type has to match contentType
+ if (mockHandler.contentType) {
+ mockHandler.headers['Content-Type'] = mockHandler.contentType;
+ }
$.each(mockHandler.headers, function(k, v) {
headers += k + ': ' + v + "\n";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment