mardi 14 juin 2016

Onclick form submit as button submit


I have a link with onclick attr to submit my form. Like this:

<a href="javascript:void(0);" onclick="myFunc()">lorem ipsum</a>

function myFunc() {
$('.ajaxform').submit();
}

The problem is.. I'm using an ajax function to do a non-refresh submit.. And I have another script like this:

jQuery(document).ready(function(){

    jQuery('.ajaxform').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 false;
    });

});

If I use a input button type submit the ajax works.. But it doesnt work using the onclick submit... How can I solve this?

Thanks.


Aucun commentaire:

Enregistrer un commentaire