Grandissimo!
Vi posto il nuovo script, se non fosse per il fatto che ho usato
if(callback != undefined) eval(callback+'();');
al posto di
$.isFunction(callback) && callback(); // non capisco come andrebbe passata la callback
sarebbe perfetto:
codice:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> </head> <body> <script type="text/javascript"> function loadScripts(urlList, callback) { loadRecursive(urlList, callback, 0); } function loadRecursive(urlList, callback, i) { (!$(document).data(urlList[i])) ? loadScript(urlList, callback, i) : checkIndex(urlList, callback, i); } function loadScript(urlList, callback, i) { $.ajax({ url: urlList[i], async: false }).done(function(msg) { $(document).data(urlList[i],true); checkIndex(urlList, callback, i); }); } function checkIndex(urlList, callback, i) { if(i+1 == urlList.length) { //$.isFunction(callback) && callback(); if(callback != undefined) eval(callback+'();'); } else loadRecursive(urlList, callback, i+1); } // TEST $(document).ready(function() { loadScripts(new Array('./uno.js'),'f1'); loadScripts(new Array('./uno.js','./due.js'),'f2'); }); </script> </body> </html>

Grandissimo!
Rispondi quotando