Home>

I want to give priority to the processing of the action destination of FORM so that jquery can be executed after that

I want to execute sample1.php and sample2.php in order

What I did
<script>
  var data;
    $('# submit'). on ('click', function () {
        $.ajax ({
            url: "sample2.php",
            type: "POST",
            cache: false,
            data: data,
        success: function (data) {
        },
        error: function (data) {
        }
    });
    });
</script>
<form name = "add_order" action = "sample1.php" method = "POST" enctype = "multipart/form-data">
// Input items such as input
<input type = "submit" value = "Register">
</form>


In sample2.php, the value of the processing result of sample1.php is required, but
There is a case where sample2.php cannot receive the value normally

  • Answer # 1

      

    I want to give priority to the processing of the action destination of FORM so that jquery can be executed after that

    This structure isnot. If you send according to<form action>, the page transitions, so the JavaScript in the page will be aborted at that point.

    Create a PHP file that internally callssample1.phpandsample2.phpand POST to it

    Transmit tosample1.phpwith Ajax

    It is necessary to change the structure drastically, such as

    .

  • Answer # 2

    Is it like this?

    <script>
    $(function () {
      $('# btn'). on ('click', function () {
        $.ajax ({
        url: "sample2.php",
        type: "POST",
        cache: false,
        data: {"b": 2},
        }). done (function (data) {
          $('# f1'). trigger ("submit");
        });
      });
    });
    </script>
    <form action = "sample1.php" method = "POST" enctype = "multipart/form-data" id = "f1">
    <input name = "a" value = "1">
    <input type = "button" id = "btn" value = "Register">
    </form>