How to call a php function from ajax?

前端 未结 4 1922
情话喂你
情话喂你 2020-12-06 01:03

I am familiar of how to get ajax to go to a php page an execute a series of things and then return json data. However is it possible to call a specific function which reside

4条回答
  •  猫巷女王i
    2020-12-06 01:38

    For AJAX request

    1. Include jQuery Library in your web page. For e.g.

      
      
    2. Call a function on button click

      
      
    3. While click on button, call create function in JavaScript.

      
      

    On the server side test.php file, the action POST parameter should be read and the corresponding value and do the action in PHP and return in JSON format e.g.

    $registration = $_POST['registration'];
    $name= $_POST['name'];
    $email= $_POST['email'];
    
    if ($registration == "success"){
        // some action goes here under php
        echo json_encode(array("abc"=>'successfuly registered'));
    }     
    

提交回复
热议问题