AJAX 到扩展的 PHP 类,所包含的类不会被传递


AJAX to a PHP class that extends, the included classes are not passed

我正在通过 AJAX 从一个 PHP 类调用一个函数,该函数扩展了另一个类,但不包含在该文件中,而是包含在不同的文件中。详细说明一下,这是我的代码:

客户:

$('.username').change(function(){
        var indexOfNumber = $(this).attr('class').indexOf('d');
        var number = $(this).attr('class').substring(Number(indexOfNumber)+1);
        $.ajax({
            url: 'class1.php',
            complete: function(response) {
                alert(response.responseText);
            },
            error: function(){
                alert("error");
            }
        });
        $('.userrole.d'+number).html(number);
    });

第1类:

class class1 extends class2
{
    function class1()
    {
        $this->class2(); << I am getting an error here
    }

我得到的错误是:

在(类 1 的位置)中找不到类"类 2"。

class2 包含在项目的 config.php 文件中,因此它不会再次包含在文件中,当我从 AJAX 调用该文件时,它似乎看不到以前包含的 PHP 文件。

有什么办法吗?

唯一的解决方法是要求 class1.php 中的必要文件。或者,您可以包含一个加载自定义自动加载器的文件,该自动加载器可以在请求类时动态加载文件。