一键提交如何在一个表单提交中调用两个动作?

时间:2019-01-09 16:33:13

标签: php mysql

我有一个PHP表单。当我单击提交按钮时,我想同时执行两个操作。我该怎么办?

<script>
     function myfunction(){

          $.ajax({
            type: 'post',
            url: 'merchants.php',
            data: $('form').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });
      }


    </script>

<div class="stdFormHeader"> New Merchant Registration</div>
<form action="" method="POST">
    <label class="stdFormLabel">Merchant name : </label><input class="stdFormInput" type="text" name="merchantName" required><br>
<!--    <label class="stdFormLabel">Business Type : </label><select class="stdFormSelect" name="shopMarket" required>-->
<!--        <option value="shop">Shop</option>-->
<!--        <option value="market">Market Place</option>-->
<!--    </select><br>-->
    <label class="stdFormLabel">Contact Person : </label><input class="stdFormInput" type="text" name="contactPerson" required><br>
    <label class="stdFormLabel">Contact Number : </label><input class="stdFormInput" type="text" name="contactNumber" required><br>
    <label class="stdFormLabel">Address : </label><textarea class="stdFormInputBox" name="address"></textarea><br>

    <input class="stdFormButton"  type="submit" name="submit" onclick="myfunction()" value="Apply">
</form>

1 个答案:

答案 0 :(得分:0)

只需再次提交:

 function myfunction(){

  $.ajax({
    type: 'post',
    url: 'merchants.php',
    data: $('form').serialize(),
    success: function () {
      alert('form was submitted');
    }
  });

  $.ajax({
    type: 'post',
    url: 'OtherFunction.php',
    data: $('form').serialize(),
    success: function () {
      alert('form was submitted again');
    }
  });
}