Skip to content

Commit

Permalink
Return null value from JSON.Parse
Browse files Browse the repository at this point in the history
JSON.parse('') will throw a syntax error (in any browser). Fix is to return a null value. I saw this when my server returned HTTP 204 No Content.
  • Loading branch information
danmarshall authored Aug 24, 2016
1 parent 80b817f commit 179fd73
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/observable/dom/AjaxObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export class AjaxResponse {
case 'json':
if ('response' in xhr) {
//IE does not support json as responseType, parse it internally
this.response = xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || '');
this.response = xhr.responseType ? xhr.response : JSON.parse(xhr.response || xhr.responseText || 'null');
} else {
this.response = JSON.parse(xhr.responseText || '');
}
Expand Down

0 comments on commit 179fd73

Please sign in to comment.