0

ajaxを使ってコンテンツを更新したい。ドロップダウン値を選択するだけで、選択されているドロップダウン値に基づいてコンテンツに新しい値が入力されます。しかし、ドロップダウンから値を選択するたびに、 Class 'db' not found エラーが返され、required_once に既に配置した他の関数も機能していないようです。これを2日間解決しようとしていますが、まだ機能していません。誰かがこれで私を助けてくれますか? ありがとう。ここに私のコードがあります:

my_file.php が読み込まれると、 course_overview_functions.php が呼び出され、else 部分が読み込まれ、適切な値が返されることに注意してください。ajax 呼び出しが実行されたときに、part が true を返した場合、class 'db' not found エラーが返されます。

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
4

1 に答える 1

0

データベース接続...そこに関数がありますが、クラスが定義されていません。class dbを定義する必要があります。

于 2013-10-09T03:35:26.943 に答える