想preLOAD的图像的getJSON调用前一段时间图像、preLOAD、getJSON

2023-09-11 01:35:45 作者:万能萌妹

我使用的getJSON呼吁下拉菜单。我想有这个Ajax调用图像preloading效果。 任何一个可以帮助我走出这个...? 我的code如下:

  $。的getJSON(myAction.do?method=fetchThruAJAX,{
    TypeNo:$(#类型)VAL()。
    AJAX:真
},功能(J){
    VAR的选择='<选项选择的值= -  1> ---选择---< /选项>';
    如果(j!= NULL){
        $每个(j.Model,功能(I,项目){
            选项​​+ ='<期权价值=+ item.SeqNo +'>
                + item.Name +'< /选项>';
        });
    }
    $(#选择模型)HTML(选项)。
});
 

解决方案

您可以做,全球使用 ajaxStart 和 ajaxStop 事件:

  $(#yourEffectContainerID)。ajaxStart(函数(){
    $(本).fadeIn(快);
})。ajaxStop(函数(){
    $(本).fadeOut(快);
});
 
图像Json表的挂载与替换

这样的话,你的效果容器将在所有的AJAX请求(这样的行为并不局限于特定的的getJSON()通话显示你发出你的下拉)。

I am using a getJson call for drop downs. I want to have an image preloading effect for this ajax call. Can any one help me out with this...?? My code follows:

$.getJSON("myAction.do?method=fetchThruAJAX", {
    TypeNo: $("#Type").val(),
    ajax: 'true'
}, function(j) {
    var options = '<option selected value="-1">---Select---</option>';
    if (j != null) {
        $.each(j.Model, function(i, item) {
            options += '<option value="' + item.SeqNo + '">'
                + item.Name + '</option>';
        });
    }
    $("select#Model").html(options);
});

解决方案

You can do that globally using the ajaxStart and ajaxStop events:

$("#yourEffectContainerID").ajaxStart(function() {
    $(this).fadeIn("fast");
}).ajaxStop(function() {
    $(this).fadeOut("fast");
});

That way, your effect container will be displayed during all AJAX requests (so that behavior is not limited to the specific getJSON() call you issue for your dropdown).