Last active
May 22, 2017 15:26
-
-
Save cballou/4989030 to your computer and use it in GitHub Desktop.
Properly handle removal of JSON Hijacking prevention method responses with jQuery.
This file contains 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
$.ajaxSetup({ | |
dataFilter: function(data, type) { | |
var prefixes = ['//', 'while(true);', 'for(;;);'], | |
i, | |
l,, | |
pos; | |
if (type != 'json' && type != 'jsonp') { | |
return data; | |
} | |
for (i = 0, l = prefixes.length; i < l; i++) { | |
pos = data.indexOf(prefixes[i]); | |
if (pos === 0) { | |
return data.substring(prefixes[i].length); | |
} | |
} | |
return data; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment