在装有Ext.Ajax.Request PHP文件,为什么不JavaScript的执行?文件、Ajax、Ext、Request

2023-09-10 15:50:41 作者:Rampant(猖狂)

我要加载的.php通过AJAX的文件,这些文件执行ExtJS的脚本,它们加载,从而改变现有的ExtJS的对象已经present在DOM。

不过,我甚至不能得到Javascript来从通过 Ext.Ajax.request 正在加载的页面执行。而任何错误都出现在Firebug的网络面板。 PHP的code被执行,而不是使用Javascript。当我打电话的页面被单独装在浏览器中,它执行Javascript的罚款。

如何获得Javascript来在装有Ext.Ajax.request页面执行?

  Ext.onReady(函数(){

    VAR menuItemStart =新Ext.Panel({
        ID:panelStart,
        标题:开始,
        HTML:这是启动菜单项。,
        CLS:'菜单项
    });

    VAR menuItemApplication =新Ext.Panel({
        ID:panelApplication,
        标题:应用程序,
        HTML:这是申请页面,
        CLS:'菜单项
    });

    VAR regionMenu =新Ext.Panel({
        区域:西方,
        驳:真,
        宽度:210,
        布局:手风琴,
        layoutConfig:{
            动画:真
        },
        项目:[menuItemStart,menuItemApplication]
    });

    VAR regionContent =新Ext.Panel({
        编号:'含量 - 面积,
        区域:中心,
        填充:'10',
        自动滚屏:真正的,
        HTML:'这是内容的
    });

    新Ext.Viewport({
        布局:边境,
        项目:[regionMenu,regionContent]
    });

    menuItemStart.header.on('点击',函数(){
       Ext.Ajax.request({
           网址:内容/ view_start.php',
           成功:函数(objServerResponse){
               regionContent.update(objServerResponse.responseText);
           }
       });
    });

    menuItemApplication.header.on('点击',函数(){
       Ext.Ajax.request({
           网址:内容/ view_application.php',
           成功:函数(objServerResponse){

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

这是通过Ajax加载该文件:

 <脚本类型=文/ JavaScript的>
    在window.onload =功能(){
        警报(从应用程序视图'); //不执行
    }

    //Ext.onReady(function(){
    //警报(从应用程序视图的ExtJS'); //不执行
    //}
< / SCRIPT>
< PHP
回声这是在应用程序视图。日期(Y-M-D H:我:S');
?>
 

解决方案 初学者指南 文件包含 LFI RFI

在你的Ajax响应窗口上的onload事件已被开除这样的功能将不会被执行,因为onload事件不会被解雇再次。尝试仅仅与警报:

 <脚本类型=文/ JavaScript的>
    警报(从应用程序视图');
< / SCRIPT>
< PHP
回声这是在应用程序视图。日期(Y-M-D H:我:S');
?>
 

更新

浏览器不以这种方式执行注入脚本,因此您可以用类似尝试:

  VAR脚本,scriptsFinder = /<脚本[^>] *>([\ S \ S] +)< \ / SCRIPT> / GI;
而(脚本= scriptsFinder.exec(responseText的))
{
   的eval(脚本[1]);
}
 

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

However, I can't even get Javascript to execute from a page that is being loaded via Ext.Ajax.request. And no errors are showing up in the Firebug Net panel. The PHP code gets executed, but not the Javascript. When I call the page being loaded by itself in the browser, it executes the Javascript fine.

How can I get Javascript to execute in 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);
           }
       });
    });
});

the file that is being loaded 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');
?>

解决方案

When you get the ajax response the onload event on the window has been already fired so the function won't be executed because the onload event won't be fired again. Try only with the alert:

<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

Browsers don't execute injected scripts in that way so you can try with something like:

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