divタグ内にフォームがありますが、フォームaction=""
送信の結果を同じdivに表示したいので、この関数を作成しました:
$(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
});
});
ただし、フォームを送信すると、フォームにロードするアクションがないため何も表示されません。同じ機能がアクション属性を持つ他のフォームでも機能するため、フォームに同じページのスクリプトを読み取らせるためにこのケースをどのように処理するかが私の質問です。フォームアクションが空のとき?