2
I wonder if it is possible to compare a value returned from an Ajax function with an external variable using jquery.
When I try to make the comparison I realize that the external variable is not recognized within the function of Ajax.
How can I make this check as follows the example?
$(document).ready(funcntion(e){ var variavel = 123; //define um valor //busca um valor para a comparação $.ajax({ url:'script.php', type:'post', dataType:'json', success: function(result){ //verifica se retornou um objeto if(typeof(result) == 'object') { //separa o valor retornado var num = result[0]; //comparar o valor retornado com a variável declarada if(num == variavel){ alert('o valor é igual'); }else{ alert('o valor é diferente'); } } } }); }
Thanks for the observations were typos and the code was not put into test to verify these conditions. I solved the problem transformed the variable into global type. Anyway thank you for your attention
– Flavio Luiz Silva