dsg7513
2018-12-04 15:35
浏览 229
已采纳

如何通过jquery AJAX调用特定的php函数

I have a jquery ajax call to a php file. However, the file contains multiple defined functions, all somewhat similar.

$conn = mysqli_connect($servername, $username, $password, $dbname);


function loadall(){
    $querystring = "SELECT location, filetype, author FROM globalposts ORDER 
BY date DESC";
    $results = mysqli_query($conn, $querystring);

    $row = mysqli_fetch_array($results, MYSQLI_ASSOC);
    echo json_encode($row);
}

function jasperbriggsload(){
    $querystring = "SELECT title, location FROM omar ORDER BY date DESC";
    $results = mysqli_query($conn, $querystring);

    $row = mysqli_fetch_array($results, MYSQLI_ASSOC);
    echo json_encode($row);
}

I have not done overloaded methods with variables, though they might work with my db structure.

My main question is how to call a specific function in an external php through ajax. if I wanted to call loadall() or jasperbriggsload() through just ajax arguments

图片转代码服务由CSDN问答提供 功能建议

我有一个jquery ajax调用php文件。 但是,该文件包含多个已定义的函数,都有些类似。

  $ conn = mysqli_connect($ servername,$ username,$ password,$ dbname); 
 
 \  nfunction loadall(){
 $ querystring =“SELECT location,filetype,author FROM globalposts ORDER 
BY date DESC”; 
 $ results = mysqli_query($ conn,$ querystring); 
 
 $ row = mysqli_fetch_array($ 结果,MYSQLI_ASSOC); 
 echo json_encode($ row); 
} 
 
function jasperbriggsload(){
 $ querystring =“SELECT title,location FROM omar ORDER BY date DESC”; 
 $ results = mysqli_query(  $ conn,$ querystring); 
 
 $ row = mysqli_fetch_array($ results,MYSQLI_ASSOC); 
 echo json_encode($ row); 
} 
   
 
 

我没有使用变量重载方法,尽管它们可能适用于我的数据库结构。

我的主要问题是如何通过ajax在外部php中调用特定函数。 如果我想通过ajax参数调用 loadall() or jasperbriggsload() 通过

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题