Why is javascript not executing in the .php file downloaded from Ext.Ajax.Request?

I want to download .php files via ajax, which execute the ExtJS script as they load, which in turn modifies the existing ExtJS objects already present in the DOM.

However, I can’t even run Javascript from the page loaded through Ext.Ajax.request. And no errors appear on the Firebug Net panel. PHP code runs, but not Javascript. When I call the page to load on its own in the browser, it executes Javascript fine.

How can I get Javascript to execute on pages loaded with Ext.Ajax.request?

Ext.onReady(function(){

    var menuItemStart = new Ext.Panel({
        id: 'panelStart',
        title: 'Start',
        html: 'This is the start menu item.',
        cls:'menuItem'
    });

    var menuItemApplication = new Ext.Panel({
        id: 'panelApplication',
        title: 'Application',
        html: 'this is the application page',
        cls:'menuItem'
    });

    var regionMenu = new Ext.Panel({
        region:'west',
        split:true,
        width: 210,
        layout:'accordion',
        layoutConfig:{
            animate:true
        },
        items: [ menuItemStart, menuItemApplication ]
    });

    var regionContent = new Ext.Panel({
        id: 'contentArea',
        region: 'center',
        padding:'10',
        autoScroll: true,
        html: 'this is the content'
    });

    new Ext.Viewport({
        layout: 'border',
        items: [ regionMenu, regionContent ]
    });

    menuItemStart.header.on('click', function() {
       Ext.Ajax.request({
           url: 'content/view_start.php',
           success: function(objServerResponse) {
               regionContent.update(objServerResponse.responseText);
           }
       });
    });

    menuItemApplication.header.on('click', function() {
       Ext.Ajax.request({
           url: 'content/view_application.php',
           success: function(objServerResponse) {

               regionContent.update(objServerResponse.responseText);
           }
       });
    });
});

file downloaded via Ajax:

<script type="text/javascript">
    window.onload=function() {
        alert('from application view'); //is not executed
    }

    //Ext.onReady(function(){
    //    alert('from application view extjs'); //is not executed
    //}
</script>
<?php
echo 'this is the application view at ' . date('Y-m-d h:i:s');
?>
0
source share
3 answers

ajax, onload , , onload . :

<script type="text/javascript">
    alert('from application view');
</script>
<?php
echo 'this is the application view at ' . date('Y-m-d h:i:s');
?>

UPDATE

, - :

var scripts, scriptsFinder=/<script[^>]*>([\s\S]+)<\/script>/gi;
while(scripts=scriptsFinder.exec(responseText))
{
   eval(scripts[1]);
}
+2

true Panel.load ( loadScripts)

regionContent.update(objServerResponse.responseText, true);
+2

, ext, update (string, true), , . , , , , ( , .)

If you use regular EXT (e.g. ext-all), you can simply add

regionContent.update(objServerResponse.responseText,true);

like that and he needs to analyze the scenarios. No dice for me, though - ext-all is too slow, but I need eval functionality. I may have to hack EXT.

0
source

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


All Articles