I would like to execute javascript in pages which I load via Ext.Ajax.request. To do this, I have to load the scripts and eval() them like this:
Ext.Ajax.request({
url: 'content/view_application.php',
success: function(objServerResponse) {
var responseText = objServerResponse.responseText;
regionContent.update(responseText);
var scripts, scriptsFinder=/<script[^>]*>([\s\S]+)<\/script>/gi;
while(scripts=scriptsFinder.exec(responseText)) {
eval(scripts[1]);
}
}
});
With JQuery, however, I can have Javascript executed in pages which are called via AJAX without resorting to eval() like this:
function replaceContentOnClick(id, pageToLoad) {
$('body').delegate(('#' + id), 'click', function(){
$.get('content/' + pageToLoad, function(data) {
$('#regionContent .x-panel-body').html(data);
});
});
}
How is it that JQuery manages to execute the javascript in the loaded page without eval()? Is there a way to load the javascript without resorting to eval() in ExtJS as well?
application/jsonit will do the necessary conversion before invoking thesuccesscallback.