gpt4 book ai didi

javascript - 即使数据库连接已定义,Ajax 调用也会返回 Class 'db' not found 错误

转载 作者:行者123 更新时间:2023-11-30 01:13:42 25 4
gpt4 key购买 nike

我想使用 ajax 更新我的内容。只需选择下拉值,内容就会根据所选的下拉值填充新值。但是每次我从下拉列表中选择一个值时,它都会返回一个 Class 'db' not found 错误,并且我已经放在 required_once 上的其他函数似乎也不起作用。我已经尝试解决这个问题 2 天了,但仍然无法正常工作。有人可以帮我解决这个问题吗?谢谢。这是我的代码:

请注意,加载 my_file.php 时,会调用 course_overview_functions.php,加载 else 部分并返回适当的值。当执行ajax调用时,如果part返回true,则返回类'db'未找到错误。

my_file.php

require_once 'includes/course_overview_functions.php';  

$course_array = array();
$pid_shown = array();
$course_array = ajax_request_val();

my_file.php(javascript部分)

$(':input').change(function(event){
event.preventDefault();
$('.minimal_table').html('<img src="../images/loading_trans.gif" style="position:relative; margin:350px; margin-top:250px;" />');
alert($(this).val());

var val_id = $(this).val();

var postData = {val_id:val_id, ajax:1 };

$.ajax({
url: "../includes/course_overview_functions.php",
async: false,
type: "POST",
data: postData,
dataType: "html",
success: function(data){
setTimeout(function(){
$('.minimal_table').html(data);
},2000);
console.log(data);
},
});

});

course_overview_functions.php

function ajax_request_val(){


$val_id = $_POST['val_id'];
$field = "course_type";

if(isset($val_id)){


$plans = db::getTable('plan',$field,$val_id);
foreach ($plans as $plan) {
if (eventAccessLevel(null, $plan['plan_id']) != EVENT_ACCESS_NONE) {
$course_array[] = getCourseDetails(null, $plan['plan_id']);
$pid_shown[] = $plan['plan_id'];
}
}
$events = db::getTable('tbl_event',$field,$val_id);
foreach ($events as $event) {
if (!in_array($event['plan_id'], $pid_shown)) {
$event_id = $event['event_id'];
if (eventAccessLevel($event_id, null) != EVENT_ACCESS_NONE) {
$course_array[] = getCourseDetails($event_id, null);
}
}
}

return $course_array;
}

else{

$plans = db::getTable('plan');
foreach ($plans as $plan) {
if (eventAccessLevel(null, $plan['plan_id']) != EVENT_ACCESS_NONE) {
$course_array[] = getCourseDetails(null, $plan['plan_id']);
$pid_shown[] = $plan['plan_id'];
}
}
$events = db::getTable('tbl_event');
foreach ($events as $event) {
if (!in_array($event['plan_id'], $pid_shown)) {
$event_id = $event['event_id'];
if (eventAccessLevel($event_id, null) != EVENT_ACCESS_NONE) {
$course_array[] = getCourseDetails($event_id, null);
}
}
}

return $course_array;
}
}

数据库连接.php

public static function getTable($tableName,$field='',$type_id='') {
if (!self::$db) self::connect();

if(!empty($type_id)){
$tableName = self::$db->escape_string($tableName);
return self::getObjects('SELECT * FROM `' . $tableName . '` WHERE `'. $field .'` = `'. $type_id .'`;');
}
else{
$tableName = self::$db->escape_string($tableName);
return self::getObjects('SELECT * FROM `' . $tableName . '`;');
}
}

错误:

Fatal error: Class 'db' not found in /home/cm/public_html/includes/course_overview_functions.php on line 207

最佳答案

你的数据库连接...你有一个函数,但没有定义类。您需要定义一个class db

关于javascript - 即使数据库连接已定义,Ajax 调用也会返回 Class 'db' not found 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19262559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com