加载jquery完成时如何隐藏加载图像

加载jquery完成时如何隐藏加载图像,jquery,ajax,Jquery,Ajax,我有这个jquery代码 else if ($(this).val() === "5") { var codefaqs = $(this).val(); $('#imgloadfaqs').show(); $("#faqsmain").attr("disabled", "disabled"); $('#faqsanswer').load('http://royta.org/somefolder/get.php',{codedgive

我有这个jquery代码

else if ($(this).val() === "5") {
        var codefaqs = $(this).val();
        $('#imgloadfaqs').show();
        $("#faqsmain").attr("disabled", "disabled");
        $('#faqsanswer').load('http://royta.org/somefolder/get.php',{codedgive:codefaqs},function(applycode){
            $('#faqsanswer').html(applycode);
            $('#imgloadfaqs').hide(2000);
            $("#faqsmain").removeAttr("disabled");
        });
    }
和显示加载图像并禁用选择框 我想当get.php完成它的工作并发送result时 加载图像已消失 但是这段代码在php显示Result之前很快就消失了
有人能帮我吗?

在函数中移动隐藏方法,从php文件中得到的结果如下:

...,codedgive:codefaqs},function(applycode){
            $('#faqsanswer').html(applycode);
            $("#faqsmain").removeAttr("disabled");
            $('#imgloadfaqs').hide(500);
        });

将从php文件中获取结果的隐藏方法移到函数中,如下所示:

...,codedgive:codefaqs},function(applycode){
            $('#faqsanswer').html(applycode);
            $("#faqsmain").removeAttr("disabled");
            $('#imgloadfaqs').hide(500);
        });

尝试将隐藏图像的代码放入done函数中。我相信这是正确的做法:

$('#faqsanswer').load('http://royta.org/module/faqs/get.php',{codedgive:codefaqs},function(applycode){
        $('#faqsanswer').html(applycode);
        $("#faqsmain").removeAttr("disabled");
        $('#imgloadfaqs').hide(500);
    });

尝试将隐藏图像的代码放入done函数中。我相信这是正确的做法:

$('#faqsanswer').load('http://royta.org/module/faqs/get.php',{codedgive:codefaqs},function(applycode){
        $('#faqsanswer').html(applycode);
        $("#faqsmain").removeAttr("disabled");
        $('#imgloadfaqs').hide(500);
    });

使用以下代码段显示和隐藏

    $(document).ready(function() {



// Setup the ajax indicator

$('body').append('<div id="ajaxBusy"><p><img src="images/loading.gif"></p></div>');



$('#ajaxBusy').css({

display:"none",

margin:"0px",

paddingLeft:"0px",

paddingRight:"0px",

paddingTop:"0px",

paddingBottom:"0px",

position:"absolute",

right:"3px",

top:"3px",

width:"auto"

});

});



// Ajax activity indicator bound to ajax start/stop document events

$(document).ajaxStart(function(){

$('#ajaxBusy').show();

}).ajaxStop(function(){

$('#ajaxBusy').hide();

});
要阅读更多关于相同的内容,请遵循

如果在所有ajax请求上使用这种方法,您将获得旋转图像,所以您不需要为所有请求编写代码,这将节省额外的工作


例如,使用下面的代码片段显示和隐藏JSFIDLE链接

    $(document).ready(function() {



// Setup the ajax indicator

$('body').append('<div id="ajaxBusy"><p><img src="images/loading.gif"></p></div>');



$('#ajaxBusy').css({

display:"none",

margin:"0px",

paddingLeft:"0px",

paddingRight:"0px",

paddingTop:"0px",

paddingBottom:"0px",

position:"absolute",

right:"3px",

top:"3px",

width:"auto"

});

});



// Ajax activity indicator bound to ajax start/stop document events

$(document).ajaxStart(function(){

$('#ajaxBusy').show();

}).ajaxStop(function(){

$('#ajaxBusy').hide();

});
要阅读更多关于相同的内容,请遵循

如果在所有ajax请求上使用这种方法,您将获得旋转图像,所以您不需要为所有请求编写代码,这将节省额外的工作


对于工作示例,请遵循JSFIDLE link

不工作。。。。!实际上,我不需要$faqsanswer.HTMLAPLYCODE;它在$'faqsanswer.load'htt'中加载。我删除$'faqsanswer.HTMLAPLYCODE;这line@masiharastooyi:您需要将隐藏图像逻辑移到从服务器$'faqsanswer.load'..ler/get.php',{codedgive:codefaqs},functionapplycode{$'faqsanswer.htmlaplycode;$'imgloadfaqs.hide2000;$faqsmain.removeattrsabled;};但是没有工作,很快就没了,是的,没有工作。。。。!实际上,我不需要$faqsanswer.HTMLAPLYCODE;它在$'faqsanswer.load'htt'中加载。我删除$'faqsanswer.HTMLAPLYCODE;这line@masiharastooyi:您需要将隐藏图像逻辑移到从服务器$'faqsanswer.load'..ler/get.php',{codedgive:codefaqs},functionapplycode{$'faqsanswer.htmlaplycode;$'imgloadfaqs.hide2000;$faqsmain.removeattrsabled;};但是还没有工作,它很快就消失了