Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ajax调用中包含另一个php文件可以工作,但javascript文件不能';t载荷_Javascript_Php_Ajax_Prototypejs - Fatal编程技术网

在ajax调用中包含另一个php文件可以工作,但javascript文件不能';t载荷

在ajax调用中包含另一个php文件可以工作,但javascript文件不能';t载荷,javascript,php,ajax,prototypejs,Javascript,Php,Ajax,Prototypejs,我有一个表单向导php页面,在它的相关javascript(我是usign prototype.js btw)中,我正在用Ajax.Updater更新一个div。真正有趣的是,成功地包含了外部php文件,但没有包含javascript文件。这是我的密码: wizard.php <div id="step1" class="tab-pane active"> <h3 class="block"><?=$core->l("report_selection"

我有一个表单向导
php
页面,在它的相关javascript(我是usign prototype.js btw)中,我正在用
Ajax.Updater
更新一个div。真正有趣的是,成功地包含了外部php文件,但没有包含javascript文件。这是我的密码:

wizard.php

<div id="step1" class="tab-pane active">
    <h3 class="block"><?=$core->l("report_selection")?></h3>
    <div class="control-group">
        <label class="control-label"><?=$core->l("report_name")?>
            <span class="required">*</span>
        </label>
        <div class="controls">
            <select id="report_selection" field="report_selection" class="m-wrap span10" appEditor="true">
                <?=combo_creator::render_reports_by_authorization();?>
            </select>
        </div>
    </div>
</div>
<div id="step2" class="tab-pane">
    <!-- Here I show external php file I include in ajax call-->
</div>
switch ($report_selection) {
     case A:
        $include_page = "last_cons_report.php";
        break;
}
if (isset($include_page)) {
    echo include $include_page;
}
<!-- Some HTML elements -->
 ...

    <script type="text/javascript" src="scripts/reportLastConsumptionFilter.js"></script>
在ajax内部,它是get\u report\u type.ajax.php

<div id="step1" class="tab-pane active">
    <h3 class="block"><?=$core->l("report_selection")?></h3>
    <div class="control-group">
        <label class="control-label"><?=$core->l("report_name")?>
            <span class="required">*</span>
        </label>
        <div class="controls">
            <select id="report_selection" field="report_selection" class="m-wrap span10" appEditor="true">
                <?=combo_creator::render_reports_by_authorization();?>
            </select>
        </div>
    </div>
</div>
<div id="step2" class="tab-pane">
    <!-- Here I show external php file I include in ajax call-->
</div>
switch ($report_selection) {
     case A:
        $include_page = "last_cons_report.php";
        break;
}
if (isset($include_page)) {
    echo include $include_page;
}
<!-- Some HTML elements -->
 ...

    <script type="text/javascript" src="scripts/reportLastConsumptionFilter.js"></script>
last_cons_report.php

<div id="step1" class="tab-pane active">
    <h3 class="block"><?=$core->l("report_selection")?></h3>
    <div class="control-group">
        <label class="control-label"><?=$core->l("report_name")?>
            <span class="required">*</span>
        </label>
        <div class="controls">
            <select id="report_selection" field="report_selection" class="m-wrap span10" appEditor="true">
                <?=combo_creator::render_reports_by_authorization();?>
            </select>
        </div>
    </div>
</div>
<div id="step2" class="tab-pane">
    <!-- Here I show external php file I include in ajax call-->
</div>
switch ($report_selection) {
     case A:
        $include_page = "last_cons_report.php";
        break;
}
if (isset($include_page)) {
    echo include $include_page;
}
<!-- Some HTML elements -->
 ...

    <script type="text/javascript" src="scripts/reportLastConsumptionFilter.js"></script>
Ajax没有加载文件的
标记,问题是,Ajax忽略了这一行。考虑使用JavaScript函数导入JavaScript代码。

这里有一个

在代码中使用函数
loadScript(url,回调)

reportSelectionChanged: function() {
switch (this.reportSelection.getValue()) {
    case A:
        new Ajax.Updater(
                'step2', get_report_type.ajax.php, 
                {
                    parameters : { 
                        reportSelection:this.reportSelection.getValue()
                    },
                    onComplete : function(){ 
                        loadScript("scripts/reportLastConsumptionFilter.js",function(){
                            // callback code here.
                        })
                        this.reportLastConsumptionFilter    = new ReportLastConsumptionFilter(this);
                    }
                });
        break;

谢谢你的提示和链接。在onComplete中使用
$.getScript
有效