Make jQuery AJAX Call to Specific PHP Functions

前端 未结 3 1870
礼貌的吻别
礼貌的吻别 2020-12-16 04:16

I am a rookie PHP developer.

I have created a PHP web project with an HTML page that contains an \'Add\' button. The name of the page is awards.html. The awards.html

3条回答
  •  猫巷女王i
    2020-12-16 04:58

    There is a method that I have discovered. Please read my explanation completely to continue. In your ajax code (I think you use jQuery), include another info 'perform', with value = php function name.

    $.post("something.php", {
      something1: something1value,
      something2: something2value,
      perform: "php_function_name"
    });
    

    Then, in your PHP file, add this piece of code at the beginning :

    
    

    Then, when you call using ajax, you can get a particular function executed. Example Usage :
    Javascript :

    $.post("example.php", {
      name: "anonymous",
      email: "x@gmail.com",
      perform: "register"
    }, function(data, status) {
      alert(data);
    });
    

    PHP file example.php:

    
    


    When you do this, automatically, function register() will get executed.

提交回复
热议问题