jQuery的AJAX加载 - 显示一个最小的加载图像。 1秒加载、最小、图像、jQuery

2023-09-10 21:21:29 作者:Brave heart

我有一个jquery ajax请求。 在页面加载显示加载图像。 这种运作良好,但我想显示加载GIF最少1秒。

i have a jquery ajax request. On page load a loading-image is displayed. this is working well, but i want to display the loading gif for a minimum of 1 second.

我已经尝试过这样的:Ajax装载机图片:?如何设置,在此期间装载器显示一个最短持续时间, 但它不工作。

I've already tried this: Ajax loader image: How to set a minimum duration during which the loader is shown? , but it's not working.

我的code是:

<div id="ajaxcontent"><img src="loader.gif" id="ajaxloading" /></div>

$.ajax({
// some code for the request
success: function () {
             $('#ajaxcontent').text(myResultText);
        }

我也试图添加.delay(1000)的文字显示过,但是这也不能正常工作。

I've also tried to add .delay(1000) before the text is shown, but this also does not work.

推荐答案

你试试这个?

   setTimeout(function() { $('#ajaxcontent').text(myResultText);},
               1000);