jQuery Ajax load and getScript -
i'm trying set site content in main area loaded via javascript (some pages take while render). however, i've run bit of logical problem when using jquery.load(), jquery.getscript , jquery.ajax().
i need able load javascript files via getscript can use these functions etc inside loaded content.
- index.php - main file being displayed (also contains #loading)
- js/script.js - file containing load code
- js/*.js - several javascript files need able use inside #maincontent after load
- load.php - file being loaded #maincontent
script.js:
$(document).ready(function() { $('#loading').fadein('fast'); $('#maincontent').load('load.php', function() { $('#loading').fadeout('fast'); $('#maincontent').fadein('slow'); }); $('#navigation li a').click(function() { $('#maincontent').fadeout('fast'); $.getscript('js/jquery.contextmenu-1.01.js'); $.getscript('js/jquery-1.5.1.min.js'); $.getscript('js/jquery-ui-1.8.12.custom.min.js'); $.getscript('js/jquery.qtip-2.0.0.min.js'); $.getscript('js/ajax.js'); $.ajax({ method: 'get', url: 'load.php', data: 'page=' + $(this).attr('rel'), beforesend: function() { $('#loading').fadein('fast'); }, complete: function() { $('#loading').fadeout('fast'); }, success: function(html) { $('#maincontent').fadein('slow'); $('#maincontent').html(html); } }); }); $.getscript('js/jquery.contextmenu-1.01.js'); $.getscript('js/jquery-1.5.1.min.js'); $.getscript('js/jquery-ui-1.8.12.custom.min.js'); $.getscript('js/jquery.qtip-2.0.0.min.js'); $.getscript('js/ajax.js'); });
as can see, i'm trying load load.php first without url parameters , interaction user. although load.php loaded correctly every time, same can't said javascript code. works, other times have refresh page few times before clean console (no errors).
the errors in console suggest me js code isn't loaded before being used inside load.php. true if load.php takes while (tested php sleep(5) function).
let me know if need clarify :)
you shouldn't load of scripts getscript. need (or all?) of them every time, why not include them on page. in addition, since your'e using jquery load jquery, i'm going have included on page. don't try load again.
Comments
Post a Comment