【问题标题】:how to combine multiple files into one page with jquery or ajax?如何使用 jquery 或 ajax 将多个文件合并到一个页面中?
【发布时间】:2012-03-30 23:10:18
【问题描述】:

我尝试为我的项目制作模板,重要的是我需要将几个 php 文件合并为一个。但我有问题,当我将其显示为模态时,一切看起来都很混乱。甚至某些功能和脚本也不起作用。有什么可以帮助或提供最佳解决方案的吗?...非常感谢任何答案。

这是我脚本的一部分...

    <div class="section">
<div class="box">
    <div class="title">Test</div>
    <div class="content">

        <div id="load_table"></div>

        // table, add button, edit and delete all is here
        // When i click edit i want show it as modal and i made a template on other files
        // but everithing get mess... any clue to solve my problem ?

        <button id="edit" class="green" type="button"><span>Edit</span></button>
        <script>
            $("#edit").click(function(){
                try {
                    var img_load = "<img src='images/pirobox/loadinfo2.gif' alt='Loading...' />";
                     $("#load_modal").html(img_load).load("template/edit_form_A.php?uid=123");
                     // I put parameter cuz i made some function on that file.
                } catch(e){ alert(e.message); }
            });

            $(document).ready(function(){ 
                // DATATABLE
                // ...
                execute("load_table","template/table_A.php?show=all");

                function execute(action,parameter){
                    if (action!=null) {
                        switch(action) {
                        case "load_table":
                            var img_load = "<img src='images/pirobox/loadinfo2.gif' alt='Loading...' />";
                            $("#load_table").html(img_load).load( parameter );
                            break;
                        case "edit_result": // Callback after modal closed
                            if ( parameter ) {
                                execute("load_table",parameter );
                            }
                            break;
                        default
                            // ...
                        }
                    }
                }
            }
        </script>

    </div>
</div>

【问题讨论】:

  • 你用过PHP的include()函数吗?
  • 在我分离的文件上?...我认为不是。我只是把它放在我的主文件中。像 index.php 或 header.php。如果我不使用 modal 或 ajax,该模板正在工作。我很困惑...@_@!
  • 当您说 modal 时,您是在说 LightBox 之类的东西吗?
  • 删除您可能在 template/edit_form_A.php 和 template/table_A.php 上拥有的任何 &lt;script&gt; 标签。
  • @cilosis 是的...我正在使用 pirobox。

标签: php jquery ajax templates


【解决方案1】:

Codeigniter 允许您在 MVC 环境中使用部分。

使用它可以让您的代码结构更加连贯。

您可能还想查看this post 以进行澄清。

【讨论】:

  • 在不使用 CI 的情况下,还有其他方法吗? ...这是我的研究项目...我只有很短的时间来完成它。另一个问题......是否可以在我从 modal 调用的文件上加载或执行功能?像“execute.php?action=test”还是“execute.php”?
猜你喜欢
  • 2012-03-17
  • 1970-01-01
  • 2011-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-03
相关资源
最近更新 更多