删除自动完成错误的微调器/加载图像

发布于 2025-01-05 16:38:30 字数 1194 浏览 0 评论 0 原文

如果自动完成出现错误/失败情况,您能否帮助我了解如何删除旋转器/加载图像?

如果我收到错误“由于意外错误,我们无法加载数据”,我会看到正在加载的图像,并且我想删除该图像。

下面是片段

  $("Autotxt").autocomplete({
    source: function (request, response) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "Webservice.asmx/GetNames",
            data: "{'prefixText':'" + request.term + "'}",
            dataType: "json",  
            success: function (data) {
                response($.map(data.d, function (item) {

                    return {
                        label: item.split('|')[0],
                        val: item.split('|')[1]
                    }
                }))
            },

            error: function (result) {

                alert("Due to unexpected errors we were unable to load data");
                ServiceFailed(result);
            },
            failure: function (response) {
                alert("Due to unexpected errors we were unable to load data");

            }
        });
    },
    select: function (event, ui) {
        txtSoID(ui.item.val);
    },
    minLength: 4
});


function txtID(val)
{
alert(val)
}

Could you please help me on how to remove the spinner/loading image if the autocomplete goes for the error/failure cases?

If i get the error "Due to unexpected errors we were unable to load data" i see the loading images and i want to remove that images.

Below is the snippet

  $("Autotxt").autocomplete({
    source: function (request, response) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "Webservice.asmx/GetNames",
            data: "{'prefixText':'" + request.term + "'}",
            dataType: "json",  
            success: function (data) {
                response($.map(data.d, function (item) {

                    return {
                        label: item.split('|')[0],
                        val: item.split('|')[1]
                    }
                }))
            },

            error: function (result) {

                alert("Due to unexpected errors we were unable to load data");
                ServiceFailed(result);
            },
            failure: function (response) {
                alert("Due to unexpected errors we were unable to load data");

            }
        });
    },
    select: function (event, ui) {
        txtSoID(ui.item.val);
    },
    minLength: 4
});


function txtID(val)
{
alert(val)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水中月 2025-01-12 16:38:30

如果您指的是通过 ui 提供的加载类,您应该能够执行以下操作:

 error: function (result) {
     $('.ui-autocomplete-loading').removeClass("ui-autocomplete-loading");
     // or .hide()
     alert("Due to unexpected errors we were unable to load data");
     ServiceFailed(result);
 },

我在 jqueryUI 开发站点位于页面底部,他们在那里讨论 css 和主题。

If you are referring to the loading class available through the ui, you should be able to do the following:

 error: function (result) {
     $('.ui-autocomplete-loading').removeClass("ui-autocomplete-loading");
     // or .hide()
     alert("Due to unexpected errors we were unable to load data");
     ServiceFailed(result);
 },

I found the class information on the jqueryUI development site at the bottom of the page where they talk about css and themes.

鞋纸虽美,但不合脚ㄋ〞 2025-01-12 16:38:30

我在您的代码中没有看到任何加载屏幕。但是您可以简单地添加该函数

var removeSpinner = function() {
    $("yourloader").hide();
}

并在失败或错误回调中调用它,例如

   error: function (result) {
        removeSpinner();
        alert("Due to unexpected errors we were unable to load data");
        ServiceFailed(result);
    }

I dont see any loading screen in your code. But you could simply add the function

var removeSpinner = function() {
    $("yourloader").hide();
}

and call it in your failure or error callback like

   error: function (result) {
        removeSpinner();
        alert("Due to unexpected errors we were unable to load data");
        ServiceFailed(result);
    }
聊慰 2025-01-12 16:38:30

对这些图像执行检查元素,检查它们的类(例如“loader”),然后将其放入错误和失败回调 $(".loader").hide() 中。

Do an inspect element on those images, check their class ('loader' for example) and then do put this in your error and failure callback $(".loader").hide().

家住魔仙堡 2025-01-12 16:38:30

改编自我在这里的答案,添加以下代码以在搜索完成后执行(即使有 0 个结果):

var __response = $.ui.autocomplete.prototype._response;
$.ui.autocomplete.prototype._response = function(content) {
    __response.apply(this, [content]);
    this.element.trigger("autocompletesearchcomplete", [content]);
};

该代码将触发一个事件 (autocompletesearchcomplete),然后您可以绑定到:

$("#q").bind("autocompletesearchcomplete", function(event, contents) {
    /* Remove spinner here */
});

希望这有帮助...

Adapted from my answer here, add the following code to execute after a search is complete (even with 0 results):

var __response = $.ui.autocomplete.prototype._response;
$.ui.autocomplete.prototype._response = function(content) {
    __response.apply(this, [content]);
    this.element.trigger("autocompletesearchcomplete", [content]);
};

That code will trigger an event (autocompletesearchcomplete) that you can then bind to:

$("#q").bind("autocompletesearchcomplete", function(event, contents) {
    /* Remove spinner here */
});

Hope this help...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文