Skip to content

Repository files navigation

#jQuery.loadscript ##Load debuggable Javascript scripts Load a JavaScript file from the server using a GET HTTP request, then execute it. This function looklike jQuery.getScript() but it use LazyLoad system. So you can debug the loaded file with a Javascript debugger. With Firebug for exemple...

[Une documentation en francais est disponibles ici: http://marcbuils.developpez.com/cours/javascript/chargez-en-ajax-des-scripts-deboguables/]

##Author Marc Buils (marc.buils@marcbuils.fr) Lei Ming (poetcoders@gmail.com)

##License LGPL v3 (http://www.gnu.org/licenses/lgpl-3.0.txt)

##Current version v0.1.1:

  • add params parameter

##Usation For default use, load only jQuery.pluginautoload script:

$.loadScript( url [, prperties] [, callback()] ) 

or

$.loadScript( url [, prperties] ).done( callback() ); 
  • url: URL of the script to Load.
  • prperties: the prperties in HTMLScriptElement.
    • Specifically, setting {lazyLoad : true} will append the script tag to <body> instead of <head>.
  • callback: function without paraleters, called when the script is loaded.

This function return a jQuery.Deferred() object.

###Example 1: Example with Deferred (recommended)

<!doctype html><htmllang="en"><head><metacharset="utf-8"/><title>Exemple of jQuery.loadScript with deferred</title><scriptsrc="http://code.jquery.com/jquery-1.8.2.min.js"></script><scriptsrc="../jquery.loadscript.js"></script><script>$(function(){$.loadScript('test.js',{'charset': 'UTF-8','lazyLoad': true}).done(function(){$('#test').test();});})</script></head><body><divid="test"></div></body></html>

###Example 2: Example with callback

<!doctype html><htmllang="en"><head><metacharset="utf-8"/><title>Exemple of loadScript with callback</title><scriptsrc="http://code.jquery.com/jquery-1.8.2.min.js"></script><scriptsrc="../jquery.loadscript.js"></script><script>$(function(){$.loadScript('test.js',{'charset': 'UTF-8'},function(){$('#test').test();});});</script></head><body><divid="test">clique ici</div></body></html>

###Example 3: Example of multiple script loading

<!doctype html><htmllang="en"><head><metacharset="utf-8"/><title>Exemple of multiple script loading</title><scriptsrc="http://code.jquery.com/jquery-1.8.2.min.js"></script><scriptsrc="../jquery.loadscript.js"></script><script>$(function(){$.when($.loadScript('test.js'),$.loadScript('test2.js',{'charset': 'UTF-8','lazyLoad': true})).done(function(){$('#test').test();$('#test2').test2();});});</script></head><body><divid="test">clique ici</div><divid="test2">clique ici</div></body></html>

###Example 4: Exemple of jQuery.loadScript with onerror

<!doctype html><htmllang="en"><head><metacharset="utf-8"/><title>Exemple of jQuery.loadScript with onerror</title><scriptsrc="http://code.jquery.com/jquery-1.8.2.min.js"></script><scriptsrc="../jquery.loadscript.js"></script><script>$(function(){$.loadScript('http://not.exist/test3.js',{'charset': 'UTF-8','lazyLoad': true,'onerror': function(oError){$("#test").html('error: '+oError.isTrusted)}}).done(function(){$('#test').test();});})</script></head><body><divid="test"></div></body></html>

About

Dedug your scripts loaded in Ajax

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages