0

想要在处理 ajax 调用时显示加载程序。但是隐藏和显示在运行时不起作用。在调试模式下没问题。我试图在 ajax 上设置超时,但没有结果。

function Rate() {
    $("#rate_navigation").hide();
    $("#rate_loader").show();

    $.ajax({
        type: "POST",
        url: "url",
        data: "data",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (msg) {
            $("#comment_result").html(msg.d);
        },
        error: AjaxCallError
    });

    $("#rate_loader").hide();
    $("#rate_navigation").show();
}
4

3 回答 3

4

beforeSendcomplete

http://api.jquery.com/jQuery.ajax/

function Rate() {

    $.ajax({
        type: "POST",
        url: "url",
        data: "data",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        beforeSend: function () {
            $("#rate_navigation").hide();
            $("#rate_loader").show();
        },
        complete: function () {
            $("#rate_loader").hide();
            $("#rate_navigation").show();
        },
        success: function (msg) {
            $("#comment_result").html(msg.d);
        },
        error: AjaxCallError
    });
}
于 2013-04-22T20:00:37.647 回答
1

将这些放入您的成功回调中:

success: function (msg) {
        $("#rate_loader").hide();
        $("#rate_navigation").show();
        $("#comment_result").html(msg.d);
    },
    error: AjaxCallError
});
于 2013-04-22T20:01:08.150 回答
1

将取消隐藏条件放在成功内

function Rate() {
$("#rate_navigation").hide();
$("#rate_loader").show();

$.ajax({
    type: "POST",
    url: "url",
    data: "data",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: false,
    success: function (msg) {
        $("#comment_result").html(msg.d);


        $("#rate_loader").hide();
        $("#rate_navigation").show();
    },
    error: AjaxCallError
});


}
于 2013-04-22T20:01:09.343 回答