简体   繁体   English

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

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

I am calling a function via AJAX from a PHP class that extends another class but is not included in that file instead it was included in a different file. 我通过AJAX从一个扩展另一个类的PHP类调用一个函数,但是不包含在该文件中,而是包含在另一个文件中。 To elaborate here's my code: 这里详细说明我的代码:

Client: 客户:

$('.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);
    });

Class1: 1类:

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

The error that I am getting is: 我得到的错误是:

Class 'class2' not found in (location of class1). 在(class1的位置)中找不到类'class2'。

class2 is included in the config.php file of the project and thus it's not included again in the files, when I call that file from AJAX it doesn't seem to see the previously included PHP files. class2包含在项目的config.php文件中,因此它不再包含在文件中,当我从AJAX调用该文件时,它似乎没有看到以前包含的PHP文件。

Any way around this? 有什么方法吗?

The only way around it is to require the necessary files in class1.php. 唯一的方法是在class1.php中要求必要的文件。 Or you could include a file that loads a custom autoloader which can dynamically load files when requesting classes. 或者您可以包含一个加载自定义自动加载器的文件,该文件可以在请求类时动态加载文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM