如何通过单击链接而不是提交按钮来获取AJAX请求

cho*_*mio 3 jquery

如何通过单击链接而不是提交按钮来进行AJAX请求?我希望一旦点击链接从输入字段POST数据

Ank*_*rma 11

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

});
Run Code Online (Sandbox Code Playgroud)