Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

What is the way for display loading with ajax sync call in chrome

Posted on by Microsoft Employee

Is there any way to display loading in chrome when using async:false in ajax call. With settimeout there is many problems when using more than one ajax sync call within settimeout funcion. And loading works well without settimeout in firefox but not working in chrome.

Output of the below code is it display loading after ajax call completes for 2 second.

Code:

function setDetails() {
            debugger;
            jQuery('loading').show();
            ajaxindicatorstart('loading data.. please wait..');

           setTimeout(function () {

            var serverUrl = location.protocol + "//" + location.host;
            var oDataUri = serverUrl + "/XRMServices/2011/OrganizationData.svc/new_pasm_tblSet";
            debugger;
            $.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 {}
                    }
                    ajaxindicatorstop();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("Error while getting license data: " + errorThrown);
                    onclickflag = false;
                }
            });
            ajaxindicatorstop();
            }, 10);
        }

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': ''

            });

            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');
        }


Please suggest any way to display loading.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the way for display loading with ajax sync call in chrome

    Hi Alagu ,Is there any difference between my posted code and your code?

  • Suggested answer
    Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 on at
    RE: What is the way for display loading with ajax sync call in chrome

    Hi Try below

    jQuery('loading').show();

    setTimeout(function(){

     //your ajax code

    },10);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans