Q:

jquery submit form via ajax

// jQuery ajax form submit example, runs when form is submitted
$("#myFormID").submit(function(e) {
    e.preventDefault(); // prevent actual form submit
    var form = $(this);
    var url = form.attr('action'); //get submit url [replace url here if desired]
    $.ajax({
         type: "POST",
         url: url,
         data: form.serialize(), // serializes form input
         success: function(data){
             console.log(data);
         }
    });
});
10
// It is simply
$('form').submit();

// However, you're most likely wanting to operate on the form data
// So you will have to do something like the following...
$('form').submit(function(e){
	// Stop the form submitting
  	e.preventDefault();
  	// Do whatever it is you wish to do
  	//...
  	// Now submit it 
    // Don't use $(this).submit() FFS!
  	// You'll never leave this function & smash the call stack! :D
  	e.currentTarget.submit();
});
7
$('#form').validate({

    ... your validation rules come here,

    submitHandler: function(form) {
        $.ajax({
            url: form.action,
            type: form.method,
            data: $(form).serialize(),
            success: function(response) {
                $('#answers').html(response);
            }            
        });
    }
});
2
$.ajax({
			    type: "POST",
			    url: "upload.php",
			    data: { name:name, mobile:mobile, address:address, city:city },		    
			    dataType: "json",
			    success: function(result){
			        			    }
			});
0

New to Communities?

Join the community