加载gif不能在IE中工作;铬

Loading gif not working in IE & Chrome

本文关键字:工作 IE gif 不能 加载      更新时间:2023-09-26

我一直在搜索,并发现了一些关于这个问题的类似问题,但事情仍然不适合我。

下面是我的函数:

function ajaxRequest(url, type, datatype, contenttype, data, displayLoadingImg){
 var result="";
 displayLoadingImg = (typeof displayLoadingImg === "undefined") ? 0 : displayLoadingImg;
 if(displayLoadingImg == 1){
    $("#loadingImgAging").css("display","block");
 }
 $.ajax({
    url:url,
    type:type,
    dataType:datatype,
    contentType: contenttype,
    data : JSON.stringify(data),
    success:function(res){
        result = res;
        if(displayLoadingImg == 1){
            $("#loadingImgAging").css("display","none");
        }
    },
    error:function(res){
        result="";
    },
    async : false
 });
 return result;
}

我怎么称呼它:

setTimeout(ajaxRequest(url,"GET","json","application/json",0,1), 500);

我试过使用beforeSend(),但它也不起作用。

注意:如果我删除async : false或把它放在true,我将得到错误Cross-Origin Request Blocked....在我的浏览器控制台

我猜您无法对本地文件进行ajax请求。有很多方法可以做到这一点,但我更喜欢这两种方法

    创建一个简单的服务器
我通常使用python来创建一个简单的服务器。在终端/控制台中输入:"python -m SimpleHTTPServer 9081"(或任何您想要的端口号)。然后,根据指定的端口打开本地主机。
    在——allow-file-access-from-files模式下打开chrome

或在Windows中使用以下代码创建批处理文件。配置前必须重新启动Chrome。

    start "chrome" "C:'Program Files (x86)'Google'Chrome'Application'chrome" --allow-file-        access-from-files
    exit

我假设您正在对另一个必须使用JSONP作为数据类型的域文件进行AJAX调用。这样你就不必让async = false

试试这个:在ajax调用之前将display设置为block,在ajax调用之后(成功或错误无关)—就在返回之前—将display设置为none。你不需要displayLoadingImg和处理它的代码。还是我错过了什么?