2011-07-23 10 views

答えて

2

post同じページに

$.ajax({ 
url:'yoururl', 
data:$("form").serialize(), 
type:'POST', 
success:function(data){ 
alert("success"); 
}, 
error:function(jxhr){ 
alert(jxhr.responseText); 
} 

}); 

jQuery.ajax() – jQuery API

0

投稿はトリックを行う必要があり、AJAXを使用してフォーム。このためにその

> <?php 
> 
> //do stuff with $_POST 
> ?> 
> 
> <html> <body> <form method="post"> 
> 
> <?php echo $result ?> 
> 
> </form> 
> </body> 
0

Fike

使用AJAX用のAJAXを使用する必要はありません、あなたの練習のためにこれを試してみてください仮定するできない

var string = $("#string").val(); 
var dataString = 'string=' + string ; 
if(string==''){ 
    alert('enter any string'); 
} 
else{ 
    $.ajax({ 
     type: "POST", 
     url: "path of php file", 
     data: dataString, 
     suceess: function(){ 
      //do something 
     }, 
     error: function(){ 
      //do something 
     } 
    }); 
} 
0

あなたが作るためにjQueryのかプロトタイプJSライブラリを使用することができます簡単なAJAX呼び出し。例:jQueryを使用すると、次のようになります。


$.ajax({ 
    url:'hashed.php', 
    data:$("form").serialize(), 
    type:'POST', 
    success: function(data){ 
    $('hashmd5').html(data.md5); 
    $('hashsha1').html(data.sha1); 
    }, 
    error: function(jxhr){ 
    alert(jxhr.responseText); 
    } 
}); 

HTMLに同じid値を使用しないでください。要素のJavaScript関数の実行を修正するには、それらは一意でなければなりません。

0

はい可能です。送信時にトリガするjavascript関数を作成し、送信ボタンを無効にしてユーザーがもう一度押すことができないようにし、最後にajax経由でサーバーをリクエストします。成功した応答ではコンテンツを更新します。 Jqueryで次のようなもの

$('.form-submit').click(function(event)) { 
     event.preventDefault(); 
     if(form is valid and not empty) { 
       $.ajax({ 
        type: "POST", 
        url: "path to script that will handle insetion", 
        data: "data from form", //like ({username : $('#username').val()}), 
        suceess: function(data){ 
         //update the content or what. data is the response got from server. you can also do like this to show feedback etc... 
         $('.feedback').html("Data has been saved successfully"); 
        }, 
        error: function(){ 
         $('.feedback').html("Data couldn't be saved"); 
        } 
       }); 
     } 

    } 
関連する問題