How to get the value of JSON with ajax and define the behavior of which div and which message to display, for example:
If JSON returns {"error":"true","message":"Algo deu errado"}
would show any div, "error" for example, with the message that JSON returned, JSON can return multiple messages ...
Another example of use is to delete information and "remove" the div with some fade-out effect, the ID being generated automatically, eg <div id="item-52">
, if everything is right {"error":"false","message":"Removido com sucesso"}
the DIV would be hidden. How can I do this?
jQuery(document).ready(function(){
jQuery('#ajax_form').submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: "POST",
url: "teste.php",
data: dados,
success: function( data )
{
alert( data );
}
});
return false;
});
});