简体   繁体   English

如何在.ready之前放置一个ajax加载器

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

I need to archive this task.i have seen this type of tasks in various sites. 我需要存档此任务。我已经在各种站点中看到了此类任务。

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

I need to show a gif before ready the document(DOM).After the ready the DOM it should disappear automatically.The gif should on the middle of the page.Any idea? 我需要在准备文档(DOM)之前显示一个gif文件。准备好DOM之后,它应该会自动消失。该gif文件应该在页面中间。

JAVASCRIPT 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();
                });
            });
        });
    });
});

Just put the code into your script, without enclosing $(document).ready() . 只需将代码放入脚本中,而无需包含$(document).ready() It will be executed as soon as the <script> tag is parsed by the browser. 一旦浏览器解析<script>标签,它将立即执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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