在我的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中的函数?如何使它们可访问?
您似乎只在index.php中包含了函数,而不是在ajax.php中。
将<?php require_once('functions.php'); ?>
添加到您的ajax.php。
将<?php require 'functions.php';?>
添加到您的ajax.php文件中。