Professional Documents
Culture Documents
Jquery Notes
Jquery Notes
jQuery Functions
jQuery Ajax
Ajax on form submit
$("#myformName").submit(function(e) {
e.preventDefault();
$.ajax({
url: 'ajax.php?action=save_data',
method: "POST",
data: $(this).serialize(),
success: function() {
alert("Success");
}
})
})
Ajax form submit with an image
$('#image-form).submit(function(e) {
e.preventDefault();
$.ajax({
url: 'ajax.php?action=save_image',
data: new FormData($(this)[0]),
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success: function() {
alert("Data successfully added", 'success')
}
}
})
})
Here contentType and processData attributes are very important, since the image cannot be
processed with serialize function.