Created
March 29, 2015 01:04
-
-
Save mohamedmansour/33802d10fcf218e28fc6 to your computer and use it in GitHub Desktop.
JavaScript Decruft JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In jQuery the easy thing to do when to decruft json responses if a javascript has: | |
// | |
// for (;;); {foo: 'bar'} | |
// | |
// Is to decruft it using ajax converters. Example | |
$.ajaxSetup({ | |
converters: { | |
"text json": function(result) { | |
return JSON.parse(result.replace('for (;;);', '')); | |
} | |
} | |
}); | |
$.ajax(url, { | |
data: data, | |
contentType: 'application/x-www-form-urlencoded', | |
type: 'POST', | |
dataType:"text json" | |
}).done(function(resp) { | |
callback(resp); | |
}).fail(function(jqXHR, textStatus ) { | |
errorCallback(textStatus); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment