在jquery中显示发送结果之前显示加载 [英] show loading before showing send result in jquery

查看:70
本文介绍了在jquery中显示发送结果之前显示加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的jquery代码,可使用ajax在jQuery模态窗口中发送内容!一切正常,没有任何问题.通常,单击发送按钮后,此代码将在1-2秒后显示结果,

I have a simple jquery code to send a content in a jQuery modal window with ajax! everything is working without any problem. in normal, after clicking on the send button, after 1-2 seconds this code showing the result,

function AddFastqpro(action) {
    var b = {};
    b[dle_p_send] = function () {
        var response = $('#dle-poke').val()
        $.post(dle_root + 'engine/ajax/fast.php', { text: response, action: action },
        function (data) {
            if (data == 'ok') {
                DLEalert(dle_p_send_ok, dle_info);
            }
            else { DLEalert(data, dle_info); }
        });
    };

    $('body').append("<div id='dlepopup' style='display:none'><textarea id='dle-poke'></textarea></div>");

    $('#dlepopup').dialog({
        autoOpen: true,
        modal: true,
        draggable: false,
        width: 350,
        dialogClass: "modalfixed",
        buttons: b
    });
};

我的问题是,如何在单击发送"之后显示结果之前添加并显示正在加载的图片?

My question is, how I can add and show a loading picture after clicking on send and before showing the result?

推荐答案

您可以通过ajaxStart()ajaxComplete()

$("#loading").ajaxStart(function(){
   $(this).show();
 });

$("#loading").ajaxComplete(function(){
   $(this).hide();
 });

$.ajax({
   url : dle_root + 'engine/ajax/fast.php',
   data: { text: response, action: action },
   beforeSend: function(){
     $("#loading").show();
   },
   complete: function(){
     $("#loading").hide();
   },
   success:  function (data) {
        if (data == 'ok') {
            DLEalert(dle_p_send_ok, dle_info);
        }
        else { DLEalert(data, dle_info); }
    });
 });

这篇关于在jquery中显示发送结果之前显示加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆