douyao2529 2016-05-11 10:15
浏览 25
已采纳

如何包含点击的表单提交按钮的值?

I must submit a form and I need to include the value of the submit button that was clicked. How can I do that? This is my code:

<form id="form_update" >
    <input type="text" class="form-control" name="title" value="" >
    <input type="hidden" name="prova" value="prova" />
    <button type="submit" name="salva" value="delete" class="btn btn-success">delete</button>
    <button type="submit" name="salva" value="modify" class="btn btn-success">modify</button>
    <button type="submit" name="salva" value="save" class="btn btn-success">save</button>
</form>
$(document).on('submit', '#form_update', function() { 
    return callAjax($(this).serialize()); 
}); 

function callAjax(data) {
    $.ajax({
        type: 'POST',
        url: 'call/function.php',
        data: data,
        success:  function(data) { 
            // code
        },
        error: function(data) { 
            alert('error'); 
        }
    });
    return false;
};  
  • 写回答

3条回答 默认 最新

  • doutangxi2144 2016-05-11 10:39
    关注

    Thanks...

    With Arun solution I get undefined val value...

    With Daan solution the problem was the same...

    But with your response I have resolved with a mix :)

    $(document).on('click', 'button', function(e) {
      e.preventDefault(); // Prevent from submitting form. 
      var buttonValue = $(this).val();
      return callAjax($('#form_update').serialize()+'&salva='+buttonValue ); 
    }); 
    

    Thanks a lot ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?