I want to load evrything in my website inside a div, so i created a function to handle form submissions to make the action loads in the same div, however the problem is some forms don’t have action action="" as the script is in the same page, so when i submit the form nothing happen inisde the div, so how i can handle this in my function?
$(document).ready(function() {
$('#mydiv').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..
//$('#mydiv').html(response); // update the DIV
$('#mydiv').fadeOut('slow',function() {
$('#collabsoft').html(response).fadeIn('slow');
});
// return false;
}
});
You can use a ternary if statement: