Add fadein effect to this jquery code

1

Good morning! I'm using the following code to get the result of a form and throw it on the page without having to reload:

<script type="text/javascript"> // Script
    jQuery(document).ready(function(){
        jQuery('#ajax_form').submit(function(){
            var dados = jQuery( this ).serialize();

            jQuery.ajax({
                type: "POST",
                url: "salvaregistro.php",
                data: dados,
                success: function( data )
                {
                    document.getElementById('resultado').innerHTML = data;
                }
            });

            return false;
        });
    });
</script>

However, this code only launches the text. I would like to know if you have how to apply the fadein effect so the text appears softer, say ...

    
asked by anonymous 18.02.2015 / 13:09

2 answers

2

Put a display: none; in the #resultado element and change it:

document.getElementById('resultado').innerHTML = data;

so:

$('#resultado').html(data).fadeIn();
    
18.02.2015 / 13:17
0

Try something like this:

<script type="text/javascript"> // Script
    jQuery(document).ready(function(){
        jQuery('#ajax_form').submit(function(){
            var dados = jQuery( this ).serialize();

            jQuery.ajax({
                type: "POST",
                url: "salvaregistro.php",
                data: dados,
                success: function( data ){
                    jQuery('#resultado').hide(0).html(data).fadeIn(400);
                }
            });

            return false;
        });
    });
</script>
    
18.02.2015 / 13:31