type='submit' を使用せず、jQuery イベントを通常のボタンにバインドし、ajax 経由でフォームを処理します。ajax 経由で結果を取得する場合、ダイアログで ajax リクエストからの結果を表示するか (PHP はダイアログでメッセージを生成します)、または成功したかどうかを確認してから適切なアクションを実行する条件を設定できます。
フォームに を含む例を次に示します。(コーディングは少し雑です)
$(document).ready(function() {
$('#submit').click(function() {
name = $('#name').val();
email = $('#email').val();
number = $('#number').val();
message = $('#message').val();
$.post("contact.php", //PHP file to send POST to
{ ajax: 'yes', name: name, email: email, number: number, message: message }, //POST fields to send
function(returned) { //What to do if the POST finishes. 'returned' is the value recieved back from the script.
if (returned == 'done') {
//PHP script returns the word 'Done'
alert('Submit successful');
});
} else {
alert('An error has occured');
}});});});