在ajax进程中Jquery Ajax发布动画?

Ali*_*hşi 0 asp.net-mvc jquery loading-image

下拉列表更改后,我在我的mvc应用程序上发布ajax帖子.

$(function () {
    $('#meters').change(function () {
        var analizor_id = $(this).val();
        if (analizor_id && analizor_id != '') {
            $.ajax({
                url: '@Url.Action("AnalizorInfoPartial", "Enerji")',
                type: 'GET',
                cache: false,
                data: { analizor_id: analizor_id },
                success: function (result) {
                    $('#TableAnalizorInfo').html(result);
                }
            });
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

落下

@Html.DropDownList("sno", new SelectList(Model, "sno", "AnalizorAdi"), "-- Analizör Seçiniz --", new { id = "meters" })
Run Code Online (Sandbox Code Playgroud)

我可以在ajax过程中显示加载图像或其他任何内容吗?(在开始 - 结束事件之间)和代码示例?

编辑

我可以这样用吗?

success: function (result) {
    $('#TableAnalizorInfo').html(result);
}
begin:function(){ 
    //show image
}
complete:function(){ 
    //hide image
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

Dar*_*rov 5

当然,你正在寻找的事件beforeSendcomplete:

if (analizor_id && analizor_id != '') {
     $.ajax({
         url: '@Url.Action("AnalizorInfoPartial", "Enerji")',
         type: 'GET',
         cache: false,
         beforeSend: function() {
             // Show your spinner
         }, 
         complete: function() {
             // Hide your spinner
         },
         data: { analizor_id: analizor_id },
         success: function (result) {
            $('#TableAnalizorInfo').html(result);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

或者您可以使用全局AJAX事件处理程序对页面上的所有AJAX请求进行全局操作:

$(document).ajaxSend(function() {
    // Show your spinner
}).ajaxComplete(function() {
    // Hide your spinner
});
Run Code Online (Sandbox Code Playgroud)