How Make AJAX REQUEST with clicking in the link not submit button

前端 未结 4 1193
悲&欢浪女
悲&欢浪女 2021-01-19 06:27

How could I make an AJAX REQUEST by clicking on a link instead of a submit button? I want once the link is clicked to POST data from input fields

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 07:09

    Here's how AJAX works:

    $('#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);
       });
    });
    

提交回复
热议问题