簡體   English   中英

如何在.ready之前放置一個ajax加載器

[英]how to put an ajax loader before .ready

我需要存檔此任務。我已經在各種站點中看到了此類任務。

$(document).ready(function () {
    $.ajax // rest of codes goes here 
    $("").load // rest of codes goes here 
});

我需要在准備文檔(DOM)之前顯示一個gif文件。准備好DOM之后,它應該會自動消失。該gif文件應該在頁面中間。

JAVASCRIPT

$(document).ready(function () {

    //calculater start
    $("#step2_6").click(function () {
        $("#calculater").load("cal/cal.html");
    });
    //calculater end

    //menu start
    $(".container").load("../../view/html/menu.html", function () {
        $(".main_menu.nav a").css("opacity", 0.3);
        $("#step1").css("opacity", 1);
        //new company start
        $("#step1_1").on("click", function () {
            //new company start setup opening....
            $(".load_window").load("../../view/html/Finalsetup.html", function () {
                //company file download
                $("#downloadLink").click(function () {
                    var companyname = $("#company_name").val();

                    $(this).attr("href", +"../../company_info/" + companyname + "/" + companyname + ".json");
                    $(this).attr("target", "_new");
                });

                //create the company through ajax...
                $("#CreateCompanyButton").click(function (event) {
                    event.preventDefault();
                    //adding step1 and step2 forms                    
                    var data = $("#companyData").serialize();
                    var dataTwo = $("#companyDataStepTwo").serialize();

                    $.ajax({
                        type: "POST",
                        url: "../../controller/business_contact_info.php",
                        data: data + "&" + dataTwo,
                        beforeSend: function () {
                            //loading a gif                        

                            $(".loader").html("<img src='../../img/loader.gif' />");
                        },
                        success: function (response) {
                            $(".main_menu.nav a").css("opacity", 1);

                            //remove gif after loaded                        
                            $(".loader").html(" ");

                            //add your infor window operning...

                            $(".load_window").load("../../view/html/addYourInfo.html", function () {
                                $("#addThePeople").click(function () {

                                    //hidden add people window is opening... 
                                    $("#addPeopleWindow").show();

                                    //select the excel sheet... 
                                    $("#excel").change(function () {

                                        //opening table window...
                                        $("#addPeopleWindow").load("../../view/html/tabledata.html", function () {});
                                    });
                                });
                            });
                        }
                    });
                });


                //adding scipt to selectors...
                $('.selectpicker').selectpicker();
                $(".drag").draggable();

                $("#previewButton").on("click", function () {

                    $("#previewSettingsView").show();
                });

                $("#previewClose").on("click", function () {
                    $("#previewSettingsView").hide();
                });

                $("#step_two").hide();
                $("#step_three").hide();
                $("#step_four").hide();

                $("#step_one_button").click(function () {
                    $("#step_one").hide();
                    $(".tell_us").css("opacity", "0.4");
                    $(".contact_info").css("opacity", "*0.2");

                    $("#step_two").show();
                });

                $("#step_two_back").click(function () {
                    $("#step_two").hide();

                    $("#step_one").show();
                });
            });
        });
    });
});

只需將代碼放入腳本中,而無需包含$(document).ready() 一旦瀏覽器解析<script>標簽,它將立即執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM