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

前端 未结 4 1194
悲&欢浪女
悲&欢浪女 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:16

    You can user JQuery and the Form serialize functionality

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

提交回复
热议问题