Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3.js - Adding a loading notification during AJAX request

I've got a chart that requires a fair amount of data, enough that it takes about 5-10 seconds to complete the d3.json() request. Is there some way to display a good old-fashioned spinner, or something to that effect during the AJAX request?

Alternatively, should I just use a jQuery AJAX request and follow the standard procedures for showing a spinner (as is described here). Just curious if anyone else has tried this...

like image 647
reptilicus Avatar asked Mar 18 '13 19:03

reptilicus


2 Answers

I use spin.js for my spinners. Then it's pretty much as you said:

var spinner = new Spinner(opts);
var target;
$(document).ready(function() {
    target = document.getElementById('spinner-box');
});

function findData() {
            $.ajax({
                beforeSend: function() {
                    spinner.spin(target);
                },
                complete: function() {
                    spinner.stop()
                },
                type: 'POST',
                url: // url,
                data: // data,
                success: function() {
                    // do something
                },
                error: function(e) {
                    spinner.stop();
                    // do something
                }
            });
        }
like image 159
moarCoffee Avatar answered Sep 30 '22 12:09

moarCoffee


I've done something like that here. The idea is to have the spinner (or other notification) on the static page and replace it inside the AJAX callback.

like image 33
Lars Kotthoff Avatar answered Sep 30 '22 14:09

Lars Kotthoff