Ajax调用的php文件中没有的函数

问题描述 投票:-2回答:2

在我的index.php中,我包含了一个包含我所有功能的php文件:

<?php require_once('functions.php'); ?>

在同一页面上,我使用jQuery进行ajax调用:

$.ajax({
           type: "POST",
           url: "ajax.php",
           data: {
               search: name
           },
           success: function(html) {
               // do something
           }
       });

在ajax.php里面是一个在functions.php中定义的函数,但是这个函数是未知的(错误:调用未定义的函数......)

为什么在ajax.php中无法访问functions.php中的函数?如何使它们可访问?

php ajax
2个回答
0
投票

您似乎只在index.php中包含了函数,而不是在ajax.php中。

<?php require_once('functions.php'); ?>添加到您的ajax.php。


-2
投票

<?php require 'functions.php';?>添加到您的ajax.php文件中。

© www.soinside.com 2019 - 2024. All rights reserved.