Assign ajax query to a variable

Asked

Viewed 56 times

-4

             $(document).ready(function(){
	$('#tabela').empty(); //Limpando a tabela
	$.ajax({
		type:'post',		//Definimos o método HTTP usado
		dataType: 'json',	//Definimos o tipo de retorno
		url: 'getDados.php',//Definindo o arquivo onde serão buscados os dados
		success: function(dados){
			for(var i=0;dados.length>i;i++){
				//Adicionando registros retornados na tabela
				


				$('#tabela').append('<tr><td>'+dados[i].date+'</td><td>'+dados[i].result+'</td></tr>');
				
				
			    }
		    }
	    });
    });


$('#tabela').append('['+dados[i].date+', '+dados[i].result+'], ');  // o retorno que preciso é nesta configuração

           

I am creating an ajax query and I would need to take the result and put it in a variable, the code I found puts the result in a table, I’ve tried everything that’s right and I can’t put the return I need into a variable.

I need this because then I will use the result to create a google chart that updates from time to time;

  • 2

    Lucas, just one correction: java != javascript

1 answer

0

var array = [];

array = JSON.parse(data);

with this is for the return of ajax go to an array

Browser other questions tagged

You are not signed in. Login or sign up in order to post.