Başarılı form gönderimini göstermek için jquery kullanarak

0 Cevap php

i aşağıdaki javascript dosya coupon.js adında var -

jQuery(document).ready(function(){
        jQuery('.appnitro').submit( function() {
$.ajax({
            url     : $(this).attr('action'),
            type    : $(this).attr('method'),
            dataType: 'json',
            data    : $(this).serialize(),
            success : function( data ) {
                        for(var id in data) {
                            jQuery('#' + id).html( data[id] );
                        }
                      }

        });

        return true;
    });

});

sms.php -

<?php
//process form
$res = "message deliverd";
$arr = array( 'content' => $res );
echo json_encode( $arr );//end sms processing
unset ($_POST);
?>

ben böyle arıyorum -

    <form id="smsform" class="appnitro"  method="post" action="sms.php"> 
... 
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit"/>
</form>
<div id="content"></div>

Now i expected that after a successful form submission the div "content" would show the message without any page refresh. But instead the page redirects to /sms.php and then outputs -

{"content":"message deliverd"}

I yanlış gidiyorum söyle. Benim javascript doğru. Kundakçı tarafından gösterilen hata yok. Or please tell some other method to acheive the reqd. functionality.

Hatta bu coupon.js işçi değil

jQuery(document).ready(function(e){
        jQuery('.appnitro').submit( function() {
$.ajax({
            url     : $(this).attr('action'),
            type    : $(this).attr('method'),
            dataType: 'json',
            data    : $(this).serialize(),
            success : function( data ) {
                        for(var id in data) {
                            jQuery('#' + id).html( data[id] );
                        }
                      }

        });

e.preventDefault();
    });

});

I sonunda dönüş fasle eklemek bile çalışmıyor. Please suggest some other method to acheive this functionality

0 Cevap