4

送信ボタンの代わりにリンクをクリックして AJAX REQUEST を作成するにはどうすればよいですか? リンクをクリックして、入力フィールドからデータを POST したい

4

4 に答える 4

12
$('selector').click(function(e){
  e.preventDefault();
  $.ajax({
       url: "<where to post>",
       type: "POST",//type of posting the data
       data: <what to post>,
       success: function (data) {
         //what to do in success
       },
       error: function(xhr, ajaxOptions, thrownError){
          //what to do in error
       },
       timeout : 15000//timeout of the ajax call
  });

});
于 2012-05-24T09:37:17.967 に答える
3

AJAX の仕組みは次のとおりです。

$('#link_id').click(function(event){
   event.preventDefault(); // prevent default behavior of link click
   // now make an AJAX request to server_side_file.php by passing some data
   $.post('server_side_file.php', {parameter : some_value}, function(response){
      //now you've got `response` from server, play with it like
      alert(response);
   });
});
于 2012-05-24T09:47:02.197 に答える
2

JQueryとフォームのシリアル化機能を使用できます

$('#A-id-selector').click(function() {
    $.ajax({
        type:'POST', 
        url: 'target.url', 
        data:$('#Form-id-selector').serialize(), 
        success: function(response) {
          // Any code to execute on a successful return
        }
    });
});
于 2012-05-24T09:40:17.980 に答える
1

jQueryで

$('#link-selector').on('click', function(event) {
    event.preventDefault();
    $.post('url', {$('form selector').serialize()}, function(json) {
        // proccess results
    }, 'json');
});
于 2012-05-24T09:36:33.673 に答える