php - script is not working inside AJAX loaded DIV, only html is loaded? -


my javascript not working after ajax response know have use $('.ajax-link').on('click', 'a', function (e){ function when using mye.preventdefault(); not working (means whole page loading instead of ajax call) , if using $('a.ajax-link').click(function (e) { ajax working fine script of ajax response page not working after ajax response . using jquery 1.10. below whole code :

$('a.ajax-link').click(function (e) {         nprogress.start();         if (msie) e.which = 1;         if (e.which != 1 || !$('#is-ajax').prop('checked') || $(this).parent().hasclass('active')) return;         e.preventdefault();         $('.sidebar-nav').removeclass('active');         $('.navbar-toggle').removeclass('active');         $('#loading').remove();         $('#dvloading').show();         var $clink = $(this);         history.pushstate(null, null, $clink.attr('href'));         $('ul li.active').removeclass('active');         $clink.parent('li').addclass('active');     });      history.adapter.bind(window, 'statechange', function () { // note: using statechange instead of popstate         var state = history.getstate(); // note: using history.getstate() instead of event.state           $.ajax({         url: state.url,         success: function (msg) {            $('#dvloading').fadeout(10);             nprogress.inc();             $('.main-sec').html($(msg).find('.main-sec').html());              nprogress.inc();             settimeout(function() { nprogress.done(); $('.fade').removeclass('out'); }, 100);             $('#loading').remove();             $('.main-sec').fadein();             var newtitle = $(msg).filter('title').text();             $('title').text(newtitle);             docready();         }     }); }); 

you can append manually scripts tag document :

$.ajax({     url: state.url,     success: function (msg) {       var scripts = $("<div>").html(msg).find( "script");       scripts.each(function(){           $('body').append($(this)[0]);         }     } }); 

or use amd pattern, take @ requirejs: http://requirejs.org/


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -