Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在chrome中使用ajax同步调用加载显示的方式是什么_Javascript_Jquery_Ajax_Google Chrome - Fatal编程技术网

Javascript 在chrome中使用ajax同步调用加载显示的方式是什么

Javascript 在chrome中使用ajax同步调用加载显示的方式是什么,javascript,jquery,ajax,google-chrome,Javascript,Jquery,Ajax,Google Chrome,在ajax调用中使用async:false时,是否有任何方法可以在chrome中显示加载。 使用settimeout,在settimeout函数中使用多个ajax同步调用时会出现许多问题。 在firefox中,加载可以在没有settimeout的情况下正常工作,但在chrome中不起作用 请建议任何其他显示装载的方式 代码: 函数setDetails(){ 调试器; jQuery('loading').show(); ajaxindicatorstart('正在加载数据..请稍候..'); se

在ajax调用中使用async:false时,是否有任何方法可以在chrome中显示加载。 使用settimeout,在settimeout函数中使用多个ajax同步调用时会出现许多问题。 在firefox中,加载可以在没有settimeout的情况下正常工作,但在chrome中不起作用

请建议任何其他显示装载的方式

代码:

函数setDetails(){
调试器;
jQuery('loading').show();
ajaxindicatorstart('正在加载数据..请稍候..');
setTimeout(函数(){
var serverUrl=location.protocol+“/”+location.host;
var oDataUri=serverUrl+“/XRMServices/2011/OrganizationData.svc/new_pasm_tblSet”;
调试器;
$.ajax({
键入:“获取”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
网址:oDataUri,
async:false,
beforeSend:函数(XMLHttpRequest){
ajaxindicatorstart('正在加载数据..请稍候..');
setRequestHeader(“接受”、“应用程序/json”);
},
成功:函数(数据、textStatus、XmlHttpRequest){
调试器;
var isDomainExists=假;

如果(data==null | | data.d.results.length如果您使用jQuery,那么在ajax启动和ajax完成事件时,有许多方法可以显示loader

仅适用于特定请求

$.ajax({
   beforeSend: function(xhr, settings){
      // write code for show loader here
   },
   complete: function(xhr, status){
      // write code for show loader here
   }

});
如果要为每个ajax请求全局设置

$( document ).ajaxStart(function() {
// write code for show loader here
});
$( document ).ajaxComplete(function() {
// write code for hide loader here
});
代码中的更正

function setDetails() {
    jQuery('loading').show();

    var serverUrl = location.protocol + "//" + location.host;
    var oDataUri = serverUrl + "/XRMServices/2011/OrganizationData.svc/new_pasm_tblSet";

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: oDataUri,
        async: false,
        beforeSend: function (XMLHttpRequest) {

            ajaxindicatorstart('loading data.. please wait..');

            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
            debugger;
            var isDomainExists = false;
            if (data == null || data.d.results.length <= 0 ) {
                debugger;
                //other code
                oDataUri1 = serverUrl + "/XRMServices/2011/OrganizationData.svc/new_pasm_tblSet";
                debugger;
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    url: oDataUri1,
                    data: jsonPO,
                    async: false,
                    beforeSend: function (XMLHttpRequest) {
                        XMLHttpRequest.setRequestHeader("Accept", "application/json");
                    },
                    success: function (data, textStatus, XmlHttpRequest) {
                        debugger;
                        checkInCRM();
                        ajaxindicatorstop();
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("Error while store license data: " + errorThrown);
                    }
                });
            }
            else {
                if (keyDetail != data.d.results[0].new_var)
                {
                    oDataUri1 = serverUrl + "/XRMServices/2011/OrganizationData.svc/new_pasm_tblSet(guid'" + id + "')";
                    debugger;
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        datatype: "json",
                        url: oDataUri1,
                        data: jsonPO,
                        async: false,
                        beforeSend: function (XMLHttpRequest) {
                            XMLHttpRequest.setRequestHeader("Accept", "application/json");
                            XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
                        },
                        success: function (data, textStatus, XmlHttpRequest) {
                            checkInCRM();
                            ajaxindicatorstop();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert("Error while store license data: " + errorThrown);
                        }
                    });
                }
                else {}
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("Error while getting license data: " + errorThrown);
            onclickflag = false;
        }
        complete: function(){
            ajaxindicatorstop();
        }
    });
}
function ajaxindicatorstart(text) {
    if (jQuery('body').find('#resultLoading').attr('id') != 'resultLoading') {
        jQuery('body').append('<div id="resultLoading" style="display:none"><div><img src="new_loading.gif"><div>' + text + '</div></div><div class="bg"></div></div>');
    }
    //
    jQuery('#resultLoading').css({
        'width': '100%',
        'height': '100%',
        'position': 'fixed',
        'z-index': '10000000',
        'top': '0',
        'left': '0',
        'right': '0',
        'bottom': '0',
        'margin': 'auto'
    });
    jQuery('#resultLoading .bg').css({
        'background': '#000000',
        'opacity': '0.7',
        'width': '100%',
        'height': '100%',
        'position': 'absolute',
        'top': '0'
    });
    jQuery('#resultLoading>div:first').css({
        'width': '250px',
        'height': '75px',
        'text-align': 'center',
        'position': 'fixed',
        'top': '0',
        'left': '0',
        'right': '0',
        'bottom': '0',
        'margin': 'auto',
        'font-size': '16px',
        'z-index': '10',
        'color': '#ffffff'
    });
    jQuery('#resultLoading .bg').height('100%');
    jQuery('#resultLoading').fadeIn(300);
    jQuery('body').css('cursor', 'wait');
}
function ajaxindicatorstop() {
    jQuery('#resultLoading .bg').height('100%');
    jQuery('#resultLoading').fadeOut(300);
    jQuery('body').css('cursor', 'default');
}
函数setDetails(){
jQuery('loading').show();
var serverUrl=location.protocol+“/”+location.host;
var oDataUri=serverUrl+“/XRMServices/2011/OrganizationData.svc/new_pasm_tblSet”;
$.ajax({
键入:“获取”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
网址:oDataUri,
async:false,
beforeSend:函数(XMLHttpRequest){
ajaxindicatorstart('正在加载数据..请稍候..');
setRequestHeader(“接受”、“应用程序/json”);
},
成功:函数(数据、textStatus、XmlHttpRequest){
调试器;
var isDomainExists=假;

if(data==null | | data.d.results.lengthThnx所有的帮助。最后我得到了答案


在beforesend中添加
jQuery('load').show();
,并将timeout设置为1000。

@Haresh-Vidja应答代码是完美的……唯一的问题是加载程序图像/div在beforesend中不会自动显示。 以下是解决方案:

        beforeSend: function () {
            $('#resultLoading').show();
            ajaxindicatorstart('loading data.. please wait..');
            //XMLHttpRequest.setRequestHeader("Accept", "application/json");
        }

beforeSend
中,当
ajax
请求被发送时,加载程序加载到达到成功的时间&
ajaxindicatorstop()
在成功中被触发。

也有同样的问题。并且得到了这个解决方案

请注意,同步请求可能会暂时锁定浏览器,从而在请求处于活动状态时禁用任何操作

如果在ajax调用中使用属性“async:false”,请尝试此解决方案

    $("div.spanner").show();
    setTimeout(function () {
        $.ajax({
                url: '@Url.Action("SaveAnswer")',
                type: "POST",
                data: data,
                async: false,
                success: function (result) {
                    console.log(result);
                    if (result.Status) {                            
                        bool = true;

                    } else {
                        alert(result.Message);
                    }
                },
            error: function (result) {
                $("div.spanner").hide();
                }
        });
    }, 10);

向我们展示在chrome中无法使用的代码。不使用同步Ajax如何?我想你不知道同步和异步调用之间的区别。你去吧–@madalinivascu我是初学者。但是,我已经在google上尽了最大努力。如果我想知道所有事情,我就不需要联系你或社区Hi Haresh、 我尝试在发送前加载show,但没有成功。嗨,Chhaya谢谢你的反馈,你能在描述中添加HTML和JS代码吗?在代码中你还调用了
ajaxindicatorstart()
function在ajax函数之前,因此它应该工作。作为此代码的输出,在完成ajax调用后,仅显示2秒钟的加载。我已在您的代码中进行了更正。请检查我的答案
    $("div.spanner").show();
    setTimeout(function () {
        $.ajax({
                url: '@Url.Action("SaveAnswer")',
                type: "POST",
                data: data,
                async: false,
                success: function (result) {
                    console.log(result);
                    if (result.Status) {                            
                        bool = true;

                    } else {
                        alert(result.Message);
                    }
                },
            error: function (result) {
                $("div.spanner").hide();
                }
        });
    }, 10);