0

I'm writing a website which heavily utilises Javascript and Ajax calls to a Python web server (Flask). The problem I'm having is that the calls usually lag or freeze the page for a brief moment giving a bad user experience. This occurs when sending a POST request to my Python script with the following Ajax-style call:

var getUniversities = function() {
    var unis;

    $.ajax({
        url: '/get/universities',
        type: 'POST',
        data: 'uid=1',
        dataType: 'json',
        async: false,
        success: function(data) {
            unis = data;
        }
    });

    return unis;
};

This is the general way I'm making Ajax requests and all of them generate some form of lag for my webpage. I believe it's because I'm trying to do it synchronously, but I can't see a way to retrieve data and have it ready for processing asynchronously.

Thanks

Shannon Rothe
  • 1,112
  • 5
  • 15
  • 26
  • 2
    don't do sync request and learn how to retrieve value from async request instead – A. Wolff Jul 07 '14 at 13:21
  • 1
    No matter how *fast* you get your synchronous AJAX request, it will always be slow enough to freeze the page enough for your users to notice. That is why synchronous AJAX requests are bad practise and strongly unrecommended. – Matt Jul 07 '14 at 13:21
  • show status as "waiting", "loading" during ajax synch request, but synch is not good idea – Ashish Kasma Jul 07 '14 at 13:22

0 Answers0