Skip to content

Instantly share code, notes, and snippets.

View shellcatt's full-sized avatar

Krasimir Gruychev shellcatt

View GitHub Profile
@shellcatt
shellcatt / getJSONP.js
Last active February 26, 2023 09:37 — forked from malsup/jsonp
$.getJSONP
// fn to handle jsonp with timeouts and errors
// hat tip to Ricardo Tomasi for the timeout logic
$.getJSONP = function(s) {
s.dataType = 'jsonp';
$.ajax(s);
// figure out what the callback fn is
var $script = $(document.getElementsByTagName('head')[0].firstChild);
var url = $script.attr('src') || '';
var cb = (url.match(/callback=(\w+)/)||[])[1];