ajax从php页面调用php函数

时间:2022-09-25 23:59:22

This is my jQuery code:

这是我的jQuery代码:

$.ajax({  
  type: "POST",  
  url: "process.php",
  success: function(msg){
  }  
});

In process.php page I have more than one function. One function is sendmail().

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

How can I call this function through ajax? I wrote the code as: url: "process.php/sendmail", but nothing happens.

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

6 个解决方案

#1


4  

With Ajax call pass some data to process.php.

使用Ajax调用将一些数据传递给process.php。

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

In php page,

在php页面中,

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

#2


8  

this is your script file

这是你的脚本文件

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

       }

and this is your process.php file

这是你的process.php文件

<?php
if(isset($_POST))
{
   if($_POST["functionName"] == "sendmail")
   {
      sendmail();
   }
}
?>

#3


2  

May below code helpful to you..

可能下面的代码对你有帮助..

 $.ajax({  
      type: "POST",  
      url: "process.php",
      data: {action: 'sendmail'},
      success: function(msg){
      }  
    });

Try this..

Thanks.

#4


0  

There is no automatic means of telling PHP to call your functions, but you can accomplish this with a simple check. Since you are trying URLs like "process.php/sendmail" you can test on the PHP variable $_SERVER['PATH_INFO']

没有自动方法告诉PHP调用您的函数,但您可以通过简单的检查来完成此操作。由于你正在尝试像“process.php / sendmail”这样的URL,你可以测试PHP变量$ _SERVER ['PATH_INFO']

if ('sendmail' == $_SERVER['PATH_INFO']) {
    sendmail();
}

#5


0  

Try using if else and process.php?fun=sendmail

尝试使用if else和process.php?fun = sendmail

if($_GET['fun'] == "Sendmail")
  sendmail()
else
  // something else 

#6


0  

to call send mail function pass a parameter to process.php file, and detect that parameter like:

调用send mail函数将一个参数传递给process.php文件,并检测该参数如:

$.ajax({  
type: "POST",  
url: "process.php",
type: "POST",
data: {sendMail: "1"},
success: function(msg){
}  
});

now in process.php USE:

现在在process.php中使用:

$_REQUEST['sendMail'] 

to detect the value..

检测值..

#1


4  

With Ajax call pass some data to process.php.

使用Ajax调用将一些数据传递给process.php。

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

In php page,

在php页面中,

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

#2


8  

this is your script file

这是你的脚本文件

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

       }

and this is your process.php file

这是你的process.php文件

<?php
if(isset($_POST))
{
   if($_POST["functionName"] == "sendmail")
   {
      sendmail();
   }
}
?>

#3


2  

May below code helpful to you..

可能下面的代码对你有帮助..

 $.ajax({  
      type: "POST",  
      url: "process.php",
      data: {action: 'sendmail'},
      success: function(msg){
      }  
    });

Try this..

Thanks.

#4


0  

There is no automatic means of telling PHP to call your functions, but you can accomplish this with a simple check. Since you are trying URLs like "process.php/sendmail" you can test on the PHP variable $_SERVER['PATH_INFO']

没有自动方法告诉PHP调用您的函数,但您可以通过简单的检查来完成此操作。由于你正在尝试像“process.php / sendmail”这样的URL,你可以测试PHP变量$ _SERVER ['PATH_INFO']

if ('sendmail' == $_SERVER['PATH_INFO']) {
    sendmail();
}

#5


0  

Try using if else and process.php?fun=sendmail

尝试使用if else和process.php?fun = sendmail

if($_GET['fun'] == "Sendmail")
  sendmail()
else
  // something else 

#6


0  

to call send mail function pass a parameter to process.php file, and detect that parameter like:

调用send mail函数将一个参数传递给process.php文件,并检测该参数如:

$.ajax({  
type: "POST",  
url: "process.php",
type: "POST",
data: {sendMail: "1"},
success: function(msg){
}  
});

now in process.php USE:

现在在process.php中使用:

$_REQUEST['sendMail'] 

to detect the value..

检测值..