ajax从php页面调用php函数

Kic*_*chu 3 php ajax

这是我的jQuery代码:

$.ajax({  
  type: "POST",  
  url: "process.php",
  success: function(msg){
  }  
});
Run Code Online (Sandbox Code Playgroud)

在process.php页面中,我有多个函数.一个函数是sendmail().

如何通过ajax调用此函数?我把代码编写为: url: "process.php/sendmail", 但没有任何反应.

小智 8

这是你的脚本文件

 $.ajax({
       url: "process.php",
       type: "POST",
       data: "functionName=sendmail",
       cache: true,
       success: function(response){

       }
Run Code Online (Sandbox Code Playgroud)

这是你的process.php文件

<?php
if(isset($_POST))
{
   if($_POST["functionName"] == "sendmail")
   {
      sendmail();
   }
}
?>
Run Code Online (Sandbox Code Playgroud)


ada*_*ost 5

随着Ajax呼叫传递一些dataprocess.php.

$.ajax({  
  type: "POST",  
  url: "process.php",
  data: {method: 'one'},
  success: function(msg){
  }  
});
Run Code Online (Sandbox Code Playgroud)

在php页面中,

if(isset($_POST["method"])) {
    $method = $_POST["method"];
    if($method=="one") {
       //call methods/functions here
    }
}
Run Code Online (Sandbox Code Playgroud)