Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cballou/4989030 to your computer and use it in GitHub Desktop.
Save cballou/4989030 to your computer and use it in GitHub Desktop.
Properly handle removal of JSON Hijacking prevention method responses with jQuery.
$.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