Validetta demos

Back to examples

Sending ajax request when form is valid


To show error messages healthy, each field must be wrapped by an element like <div>

<form id="exm" method="POST" action="#">
        <label>Required :</label>
        <input type="text" name="name" data-validetta="required">
        <label>Email :</label>
        <input type="text" name="email" data-validetta="email">
    <button type="submit">Submit</button>
    <button type="reset">Reset</button>
        onValid : function( event ) {
            // this -> form object
            // this.form is form element
                url : 'ajax.json',
                data : $(this.form).serialize(),
                dataType : 'json',
                beforeSend : function(){
                    console.log('Started request !');
            .done( function( data ){
                alert('Student Name : '+data.student[0].name+' Student No :'+data.student[0].no);
            .fail( function( jqXHR, textStatus ){
                console.log(textStatus+':'+jqXHR.status+' : '+jqXHR.statusText);
            .always( function( result ){ console.log('Request done !!');