weixin_33674976 2015-10-28 15:24 采纳率: 0%
浏览 151

设置ajax调用的延迟

I am trying to add a small delay (2 sec) between the loader icon and the success with the data as html.

What I have tried to use is the setTimeout and put in a delay number. This is not working, so I was hoping you could show me what the correct way is.

My ajax code:

<script type="text/javascript">

$(function () {

    var delay = 2000;

    var res = {
        loader: $("<div />", { class: "loader" })
    };

    $('#search').on('click', function () {
        $.ajax({
            type: 'GET',
            url: "@Url.Action("Find", "Hotel")",
            datatype: "html",
            beforeSend: function () {
                $("#group-panel-ajax").append(res.loader);
                setTimeout(delay);
            },

            success: function (data) {
                $("#group-panel-ajax").find(res.loader).remove();
                $('#group-panel-ajax').html($(data).find("#group-panel-ajax"));
            }
        });
        return false;
    });
});

</script>

Right now it runs really fast. Hope someone can help.

  • 写回答

4条回答 默认 最新

  • weixin_33712987 2015-10-28 15:30
    关注

    here is something i found when i wanted to do the same :

    function doStuff()
    {
      //do some things
      setTimeout(continueExecution, 10000) //wait ten seconds before continuing
    }
    
    function continueExecution()
    {
       //finish doing things after the pause
    }
    

    hope it will help ya

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题