Created
June 18, 2009 18:18
Revisions
-
gf3 revised this gist
Aug 5, 2010 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,13 +17,13 @@ * ) **/ var loadJSONP = (function loadJSONP_outer( window, document, undefined ) { var uuid, head, main_script uuid = 0 head = document.head || document.getElementsByTagName( 'head' )[0] main_script = document.createElement( 'script' ) main_script.type = 'text/javascript' return function loadJSONP_inner( url, callback, context ) { var name, script // INIT name = '__jsonp_' + uuid++ if ( url.match(/\?/) ) -
gf3 revised this gist
Aug 5, 2010 . 2 changed files with 50 additions and 36 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,36 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ /** * loadJSONP( url, hollaback [, context] ) -> Null * - url (String): URL to data resource. * - hollaback (Function): Function to call when data is successfully loaded, * it receives one argument: the data. * - context (Object): Context to invoke the hollaback function in. * * Load external data through a JSONP interface. * * ### Examples * * loadJSONP( * 'http://www.gigpark.com/businesses/runlevel6.json', * function(data) { * console.log(data) * } * ) **/ var loadJSONP = (function loadJSONP( window, document, undefined ) { var uuid, head, main_script uuid = 0 head = document.head || document.getElementsByTagName( 'head' )[0] main_script = document.createElement( 'script' ) main_script.type = 'text/javascript' return function( url, callback, context ) { var name, script // INIT name = '__jsonp_' + uuid++ if ( url.match(/\?/) ) url += '&callback=' + name else url += '?callback=' + name // Create script script = main_script.cloneNode() script.src = url // Setup handler window[name] = function( data ) { callback.call( ( context || window ), data ) head.removeChild( script ) script = null delete window[name] } // Load JSON head.appendChild( script ) } })( window, document ) -
gf3 revised this gist
Jun 18, 2009 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ var loadJSONP = (function(){ var unique = 0; return function(url, callback, context) { // INIT var name = "__jsonp_" + unique++; if (url.match(/\?/)) url += "&callback="+name; else url += "?callback="+name; -
gf3 revised this gist
Jun 18, 2009 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,14 @@ /* loadJSONP( 'http://www.gigpark.com/businesses/runlevel6.json', function(data) { console.log(data); } ); */ var loadJSONP = (function(){ var unique = 0; return function(url, callback, context) { -
gf3 revised this gist
Jun 18, 2009 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,6 +15,7 @@ var loadJSONP = (function(){ window[name] = function(data){ callback.call((context || window), data); document.getElementsByTagName('head')[0].removeChild(script); script = null; delete window[name]; }; -
gf3 created this gist
Jun 18, 2009 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ var loadJSONP = (function(){ var unique = 0; return function(url, callback, context) { // INIT var name = "_jsonp_" + unique++; if (url.match(/\?/)) url += "&callback="+name; else url += "?callback="+name; // Create script var script = document.createElement('script'); script.type = 'text/javascript'; script.src = url; // Setup handler window[name] = function(data){ callback.call((context || window), data); document.getElementsByTagName('head')[0].removeChild(script); delete window[name]; }; // Load JSON document.getElementsByTagName('head')[0].appendChild(script); }; })();