简体   繁体   中英

how to combine multiple files into one page with jquery or ajax?

I try to making a template for my project, the important thing is I need to combine few php files became one. but i have problem, when I display it as modal, all looks mess. even some of the functions and scripts didn't working. is there anything that can help or provide the best solution ?... really appreciate for any answers.

This is part of my script...

    <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>

Codeigniter allows you to use partials in an MVC environment.

Using it will enable you to structure your code more coherently.

You might also want to look at this post for clarification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM