How can I execute Javascript through an ExtJS AJAX call without eval (), how can I use jQuery?

I would like to execute javascript on the pages that I load through Ext.Ajax.request. To do this, I have to download the scripts and eval()them as follows:

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]);
        }
    }
});

However, with jQuery, I can run Javascript on pages that are invoked through AJAX without resorting to the eval()following:

function replaceContentOnClick(id, pageToLoad) {
    $('body').delegate(('#' + id), 'click', function(){
        $.get('content/' + pageToLoad, function(data) {
            $('#regionContent .x-panel-body').html(data);
        });
    });
}

How does jQuery manage to execute javascript on a loaded page without eval()? Is there a way to load javascript without resorting to eval()in ExtJS?

+3
source share
3 answers

eval. , :

eval is evil

eval ( , , setTimeout setInterval) JavaScript . , . eval JavaScript.

( http://www.jslint.com/lint.html)

, " ", , .

JSON2.js(http://www.json.org) JSLint, :

/*jslint evil: true */

, ?

+3

, jQuery (http://code.jquery.com/jquery-latest.js) Ctrl + F globalEval: function. , JavaScript. , script DOM. extJS, . "script" "script", , script - . globalEval.

+1

At the risk of sounding like a broken record , see my other answer regarding loadScriptsconfig. You should consider sticking to the same question when it is simply a continuation of what you have already asked, rather than starting new questions.

+1
source

Source: https://habr.com/ru/post/1778077/


All Articles