1

このフォームをajaxで処理したいのですが、送信する前にデータをどのように処理する必要があるかが完全にはわかりません。これは私のフォームであり、それを出力する式エンジンモジュールであるため、php関数に何が起こるかはわかりません。

<form id="bookmark_form_entry_106" class="bookmark_form" name="bookmark_form" method="post" action="http://mysite.com//S=1b73e2e22729ccf0613b758ecc7e2631fab28745/">

<div class="hiddenFields">
<input type="hidden" name="XID" value="438068dba50235d9992e1492a6171e892f7bac60">
<input type="hidden" name="ACT" value="50">
<input type="hidden" name="RET"     value="http://mysite.com/S=1b73e2e22729ccf0613b758ecc7e2631fab28745/video/esegui_slq_1">
<input type="hidden" name="type" value="entry">
<input type="hidden" name="data_id" value="106">
<input type="hidden" name="site_id" value="3">
</div>


<input type="submit" value="add bookmark">

</form> 

jQuery $ .ajax();を使用します。しかし、フォームデータの処理方法がわかりません。

$.ajax({  
type: "POST",  
url: "http://mysite.com//S=1b73e2e22729ccf0613b758ecc7e2631fab28745/",  // is this correct?
data: ,  // what data should go there?
success: function() {  
 // wohoo, this works! 
}  
});  

私はフォームの初心者なので、POSTスクリプトがデータを処理する方法についてもっと知る必要があるのか​​、それともフォーム自体の内容を知っているだけで十分なのかわかりません。

また、Webインスペクター(またはfirebug)でこれをテストする方法にも興味があります。ありがとうございます。

4

2 に答える 2

4

データを取得するには、jQueryのシリアル化関数(http://api.jquery.com/serialize/)が必要です。

var data = $('#form_id').serialize()

次にdata、AJAX呼び出しで変数を使用します。

フォームの送信をどの程度正確に処理しているかにもよりますが、送信された$(this)フォームを変数にすることができるはずです。

したがって、呼び出しを作成するための優れた方法は次のとおりです。

$.ajax({  
type: "POST",  
url: $(this).attr('action'),  // read the action attribute of the form
data: $(this).serialize(),  // what data should go there?
success: function() {  
 // wohoo, this works! 
}  
});  
于 2012-09-20T09:00:05.480 に答える
0

投稿値の設定にdata使用する場合$('#bookmark_form_entry_106').serialize()

$.ajax({  
    type: "POST",  
    url: "http://mysite.com//S=1b73e2e22729ccf0613b758ecc7e2631fab28745/",  // is this correct?
    data: $('#bookmark_form_entry_106').serialize(),  // what data should go there?
    success: function() {  
     // wohoo, this works! 
    }  
});
于 2012-09-20T09:01:18.083 に答える