AJAX MySQL查询进度栏

Is it possible to show current MySQL query progress with AJAX? I have simple AJAX request that get data from a MySQL database but sometimes it take a while like 5 seconds (it depends on row count).

Here is the code:

$.ajax({
        xhr: function()
                  {
                    var xhr = new window.XMLHttpRequest();

                    //Download progress
                    xhr.addEventListener("progress", function(evt){

                         var percentComplete = evt.loaded / evt.total;

                        console.log(percentComplete);

                    }, false);
                    return xhr;
                  },

        url: '/main/pw_RedrawGraph/',
        type: 'POST',
        dataType: 'json',
        data: {
            date_from: date_from,
            date_to:date_to
        },
        success:function(data){
            console.log(data)
        }
    });

As you see I have tried do it with xhr progress but not working because evt.loaded / evt.total is infinite

Any idea how to resolve that problem?

Is this for you, or a user?

If you have a low variance in execution times.. I'd be tempted to guess how long it takes, either by benchmarking a few times or by storing a rolling average of the time it takes to run.

I'd then build a progress bar that fills up at a slightly slower than appropriate speed so that it rarely fills.

Failing that I'd just use a spinner.