且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AJAX调用后,PHP函数

更新时间:2023-02-01 21:10:26

您将需要运行在第一个成功的另一个AJAX调用。

JavaScript不能用PHP直接交互,因此,你不能调用从AJAX调用成功/完整功能的PHP函数。

When a user submits the form on my page I use AJAX to submit the information without refreshing the page. After the user submits the information I want to run a PHP function that I have already written that displays the information. Is this possible or do I need to run another ajax function to update after

    $(function () {
       $('add').on('submit', function (e) {
          $.ajax({
            type: 'post',
            url: 'submit.php',
            data: $('this').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });
          e.preventDefault();
          updateWords(); //PHP FUNCTION
        });
      });

You will need to run another AJAX call on success of the first one.

JavaScript cannot interact with PHP directly and therefore you can't call a PHP function from the success/complete function of the AJAX call.