2
What I’m doing wrong?
var GETEstado = $(this).val(json[0].GETEstado);
alert (GETEstado);
The Alert is exhibiting
[Object Object]
My complete code:
$(document).ready(function () {
$(".transportadora").click(function () {
id = $("input[type=radio][name='transportadora']:checked").val();
estado = $("#estado2").val();
$.getJSON("cotacoesBuscaTransportadora.php", {
id_transportadora: id,
estado: estado
}, function (json) {
$("#estadoT").val(json[0].estadoT);
$("#valorCap").val(json[0].valorCap);
$("#valorExcedCap").val(json[0].valorExcedCap);
$("#valorAloremCap").val(json[0].valorAloremCap);
$("#prazoCap").val(json[0].prazoCap);
var GETEstado = JSON.stringify(json[0].GETEstado);
var ResulteZero = JSON.stringify(json[0].ResulteZero);
});
});
});
jQuery(function ($) {
if (GETEstado == "") {
$.gritter.add({
title: 'Erro',
text: 'Preencha os dados do destinatário',
class_name: 'gritter-error gritter-center'
});
}
if (ResulteZero == 0) {
$.gritter.add({
title: 'Erro',
text: 'Essa transportadora não entrega no estado de destino ou destino não cadastrado.',
class_name: 'gritter-error gritter-center'
});
}
});
Using the
JSON.stringify
worked, what I’m not able to do is take the value of the variable to another function where will show a message on the screen. http://jsfiddle.net/zLqf3ccr/, see this link.– Tiago
James, this is what you want: http://jsfiddle.net/zLqf3ccr/1/ ?
– Sergio
@Sergio, yes, but you need to be inside
jQuery(function($) {
otherwise does not load the message.– Tiago
No, but you might have to
jQuery
in time of$
: http://jsfiddle.net/zLqf3ccr/2/– Sergio
@Sergio again, thank you very much!
– Tiago