4

I am using flex slider on a page and page also making an ajax call for other job. My issue is when user load the page, ajax call block flex slider until ajax request has not been completed. After completed ajax request, flex slider loaded successfully. If i remove ajax script then flex slider is loading very fast.

Flex slider and ajax request both are written between this code...

$(document).ready(function(){
    $('#carousel').flexslider({
        animation: "slide",
        controlNav: true,
        animationLoop: true,
        slideshow: false,
        itemWidth: 100,
        itemMargin: 15,        
        asNavFor: '#slider'        
    });

    // Rest code of slider will come here

    // Ajax code start from here    
    $.ajax({ 
            type: "GET",
            async:false,
            url: prefixUrl, 
            success: function(results) { 
                    $(results).insertBefore('.event_container'); 
            }
        });

});

Please suggest any ideas so that ajax call should not block flex slider.

Thank you

5
  • 1
    Don't set async to false if you don't want it to block. Commented Jul 8, 2016 at 5:23
  • @kinakuta# Also not working after changing async:true Commented Jul 8, 2016 at 5:28
  • No error in console Commented Jul 8, 2016 at 5:43
  • You say "not working" ... what DOES happen, what do you EXPECT instead Commented Jul 8, 2016 at 6:09
  • "not working" means same happening Commented Jul 8, 2016 at 6:18

2 Answers 2

3

Async false will wait till your operation get complete.

try this :

$.ajax({ 
        type: "GET",
        async:true,
        url: prefixUrl, 
        success: function(results) { 
                $(results).insertBefore('.event_container'); 
        }
    });

//update 2 :

Actually it is happening since you have added Ajax in ready function so till your ajax is running page ready event is not getting completed. try removing it from document ready.

Sign up to request clarification or add additional context in comments.

8 Comments

I have added new comments please try that..hope that will solve your issue
Ya # After using async:true, it's working but ajax is not giving proper response means async:false giving 6 column results but async:true, giving 3 columns result. Can you suggest how to handle this?
Your ajax have any dependancy?
Can you create a fiddle for this..i am not able get your problem completely
async: false is okay but async: true is not giving response in sequence jsfiddle.net/anilk1797/y7yhd/49 I want same result but using async: true.
|
0

We use ajax for not getting post-back operation and in your code you mentioned like async: false which leads to synchronous ajax call. Synchronous ajax call makes you to stop/block until you get the response for the previous request. So try this:

$.ajax({ 
    type: "GET",
    url: yourURL, 
    success: function(results) { 
            $(results).insertBefore('.event_container'); 
    },
    async:true
});

1 Comment

Changing async:true working fast but again flex slider loads after ajax request complete. Is there any other option so that flex slider and ajax call don't depends on each other?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.