___ ___ erkimt Reading json correctly to generate the data for the chart (Ajax and Morris) ______ qstntxt ___

link

I am not able to return json via ajax, I tried with console.log but it is returning the function itself that I mounted

%pre%

How do I return the json I had ridden before?

All this is to generate the graph, but it is not reading json correctly.

I'm following the tutorial on this site

link

    
______ azszpr99132 ___
%pre%     
___

0

link

I am not able to return json via ajax, I tried with console.log but it is returning the function itself that I mounted

function (){
            var json = null;
            $.ajax({
                async: false,
                global: false,
                url: "http://localhost:8000/uf/",
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    json = data;
                    console.log(json);
                }
            });
            return json;
        }here

How do I return the json I had ridden before?

All this is to generate the graph, but it is not reading json correctly.

I'm following the tutorial on this site

link

    
asked by anonymous 19.11.2015 / 03:03

1 answer

-1
<script type="text/javascript">
    // Lê os dados, que já estão em json
    var json = function(callback){
        var json = null;
        $.ajax({
            url: "http://localhost:8000/uf/",
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                json = data;
                callback(data);
            }
        });
        return json;
    };

    // Gera o gráfico de barras
    var grafico = function(dados) {
        Morris.Bar({
            element: 'barchart',
            data: dados,
            xkey: 'uf',
            ykeys: ['quant'],
            labels: ['quant'],
            hideHover: 'auto',
            resize: true,
        });
    };

    // Chamando a função para gerar o gráfico
    json(grafico);

    // Caso queira imprimir os dados no console
    /* json(function(json){
        console.log(json)
    }); */

</script>
    
19.11.2015 / 05:03