javascript - Ajax request to get HTML doesn't execute scripts -


i've seen question many times here many different answers. code stopped working when moved jquery 1.5.1 1.9.1.

$.ajax(     {         type: 'get',         url: mappath($(this).attr('path')),         cache: false,         data: '{}',         datatype: 'html',         success: function (result) {             result = $.parsehtml(result);              $('#dialog').html(result);             $('#dialog').dialog('open');             }         }     }); 

the result contains link javascript file src attribute. before upgraded script loaded , executed after being added #dialog container. not. 1 suggestion tried after parsehtml() method:

$.getscript("/myscript.js"); 

that works that's not want. loading container shouldn't have know loaded container. if loaded container needs script include script needs run when container loaded.

i've tried suggestions of finding script elements eval() them. once parsehtml() scripts aren't there anymore. why have use parsehtml() see other question.

maybe these things related.

it's unsafe begin loading scripts html due way browser handle (it may inconsistently execute before or after html ready manipulated). instead, parse string can load scripts later.

$.ajax({     type: 'get',     url: mappath($(this).attr('path')),     cache: false,     success: function (result) {         result = result.replace(/<script/ig, '<div class="i-script"')                        .replace(/<\/script/ig, '</div');         result = $.parsehtml(result);         var scripts = $(result).find('.i-script').addback().filter('.i-script').detach();         $('#dialog').html(result);         scripts.each(function(i,script){             $.getscript($(script).attr('src'));         });         $('#dialog').dialog('open');     } }); 

obviously, code above work external scripts, modify work inline.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -