I have a form inside a div tag, but with action=""
, and i want the result of form submission abppear in the same div, so i created this function:
$(document).ready(function() {
$('#div1').delegate('form', 'submit', function() { // catch the form's submit events inside the div
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
//$('#div1').html(response); // update the DIV
$('#div1').fadeOut('slow',function() {
$('#div1').html(response).fadeIn('slow');
});
}
});
return false; // cancel original event to prevent form submitting
});
});
however when i submit the form, nothing appears because the form has no action to be loaded, the same function works with other forms having action attribute, so my question is how to handle this case to make the form read the script in the same page when the form action is empty?