Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
在Javascript函数的持续时间内显示微调器_Javascript_Jquery - Fatal编程技术网

在Javascript函数的持续时间内显示微调器

在Javascript函数的持续时间内显示微调器,javascript,jquery,Javascript,Jquery,我有一个调用AJAX的函数,它大约需要5秒钟才能完成执行。我有一个隐藏的微调器glyphicon,当用户通过$(“.glyphicon刷新”).removeClass(“隐藏”)(hidden是bootstrap中的一个函数,工作正常,它显示轮子旋转。但是,我希望当函数完成时,轮子应该再次隐藏。但是,如果我在函数末尾添加类hidden,或者如果我这样做。hide()在jQuery中,旋转的轮子根本就不会出现。有没有办法让旋转的轮子或其他东西在Javascript函数期间出现?我搜索了一下,只找到

我有一个调用AJAX的函数,它大约需要5秒钟才能完成执行。我有一个隐藏的微调器glyphicon,当用户通过
$(“.glyphicon刷新”).removeClass(“隐藏”)
(hidden是bootstrap中的一个函数,工作正常,它显示轮子旋转。但是,我希望当函数完成时,轮子应该再次隐藏。但是,如果我在函数末尾添加类hidden,或者如果我这样做。hide()在jQuery中,旋转的轮子根本就不会出现。有没有办法让旋转的轮子或其他东西在Javascript函数期间出现?我搜索了一下,只找到了针对某些框架(如MeteorJS)的问题,而不仅仅是普通代码

编辑:

以下是我正在运行的部分代码:

$(document).ready(function() {
    var cont = " .continue-btn";
    $("#section-one" + cont).click({id: "#section-one", next: "#section-two"}, submitSection);
    $("#section-two" + cont).click({id: "#section-two", next: "#section-three"}, submitSection);
});

function submitSection(event) {
    $(event.data.id + " .glyphicon-refresh").removeClass("hidden");
    var there_are_errors = false;
    var radio_element = '';
    var form = event.data.id + ' form';
    $(form + ' input, ' + form + ' select, ' + form + ' radio, ' + form + ' number').each(
        function(i) {
            var input = $(this);
            if (input.is(':radio')) {
                if (this.checked) {
                    //continue
                } else if (radio_element != this.name) {
                    radio_element = this.name;
                    //continue
                } else {
                    there_are_errors = false
                    return false;
                }
            }

            if (typeof(input.attr('class')) == "string" && input.attr('class').indexOf('required') !== -1 && input.val() == '') {
                there_are_errors = false
                return false;
            }
        }
    );
    if (there_are_errors) {
        $(event.data.id + " .glyphicon-refresh").addClass("hidden");
        return false;
    }
    else {
        $.ajax({
            url: '/ajax/form',
            type: 'POST',
            data: $(form).serialize(),
            success: function(data) {
                $(err).removeClass('error-message').text("");
                $(event.data.next + " .section-header").removeClass('disabled').trigger('click');
                if (typeof event.data.submit !== 'undefined') {
                    $("#submit-message p").addClass("submit-message").text(data);
                }
            },
            failure: function(error) {
                $(err).addClass('error-message').text("An error occurred while processing your information.");
                $("html, body").animate({scrollTop: $(event.data.id).offset().top}, 250);
            }
        });
        $(event.data.id + " .glyphicon-refresh").addClass("hidden");
        return true;
    }
}

首先,你应该发布你的代码。 我假设你只是在做这样的事情:

function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...); // make ajax call
  $(".glyphicon-refresh").addClass("hidden"); // hide spinner
}
function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...).always(function() { // .always() will be called after
                                  // ajax request finished 
                                  //(failed or success - doesnt matter)
     $(".glyphicon-refresh").addClass("hidden"); // hide spinner
  }); // make ajax call      
}
这将显示微调器并立即隐藏它,而无需等待ajax函数返回,因为$.ajax是异步的。 你应该这样做:

function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...); // make ajax call
  $(".glyphicon-refresh").addClass("hidden"); // hide spinner
}
function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...).always(function() { // .always() will be called after
                                  // ajax request finished 
                                  //(failed or success - doesnt matter)
     $(".glyphicon-refresh").addClass("hidden"); // hide spinner
  }); // make ajax call      
}

首先,你应该发布你的代码。 我假设你只是在做这样的事情:

function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...); // make ajax call
  $(".glyphicon-refresh").addClass("hidden"); // hide spinner
}
function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...).always(function() { // .always() will be called after
                                  // ajax request finished 
                                  //(failed or success - doesnt matter)
     $(".glyphicon-refresh").addClass("hidden"); // hide spinner
  }); // make ajax call      
}
这将显示微调器并立即隐藏它,而无需等待ajax函数返回,因为$.ajax是异步的。 你应该这样做:

function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...); // make ajax call
  $(".glyphicon-refresh").addClass("hidden"); // hide spinner
}
function getData() {
  $(".glyphicon-refresh").removeClass("hidden"); // show spinner
  $.ajax(...).always(function() { // .always() will be called after
                                  // ajax request finished 
                                  //(failed or success - doesnt matter)
     $(".glyphicon-refresh").addClass("hidden"); // hide spinner
  }); // make ajax call      
}

在ajax回调中添加类。请显示您的js ajax回调请在帖子中添加您正在使用的相关代码-这将帮助用户建议适当的解决方案。添加隐藏控制盘的代码。您可能有一个错误。请在ajax回调中添加该类。请显示您的js ajax回调请添加您正在使用的相关代码我们的帖子将帮助用户建议一个合适的解决方案。添加隐藏轮子的代码。你可能在iThanks中有一个bug,这很好地工作。但是,不是使用ajax(…)。始终,我将其作为ajax调用的参数之一包含在中。我有成功,也有失败,所以我只是在那之后添加了始终,现在我发现我的解决方案实际上不起作用,而你的解决方案起作用了,所以感谢你,这非常有效。但是,我没有使用ajax(…).总是,我把它作为ajax调用的参数之一包含在其中。我有成功,也有失败,所以我只是在那之后添加了always,现在我发现我的解决方案实际上不起作用,而你的解决方案起作用了,所以谢谢你