Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery ajax使用require一次性调用php脚本_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript Jquery ajax使用require一次性调用php脚本

Javascript Jquery ajax使用require一次性调用php脚本,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个ajax请求,如: $.ajax({ type: "GET", url: "services/Test.class.php", data: "call=getTest", success: function (data) { alert(data); }, error: function (response) { alert("Error getting php file"); } }); 因此,在

我有一个ajax请求,如:

$.ajax({
    type: "GET",
    url: "services/Test.class.php",
    data: "call=getTest",
    success: function (data) {
        alert(data);
    },
    error: function (response) {
        alert("Error getting php file");
    }
});
因此,在我的类(Test.class.php)中,我有一个
getTest()
函数和一个
require\u once('OtherPHP')

测试此代码时,我在require once中有一个错误:

没有这样的文件或目录

在我的
警报(数据)

如何修复它?

似乎您在Test.class.php中包含了一个错误的
OtherPHP
文件路径。使用
file\u exists()
函数在
Test.class.php

if (file_exists(`OtherPHP.php`)) {
    require_once(`OtherPHP.php`)
} else {
    echo "The file `OtherPHP.php` does not exist";
}

您无法直接从ajax调用该类

  • 创建新的php文件say test.php
在test.php中

   include("Test.class.php");    
   $test = new Test();
   $test ->getTest(); //print the getTest outpout here 
Javascript:

     $.ajax({
        type: "GET",
        url: "test.php",

        .....

不,我的错误在Test.class.php中,所以我认为我有一个好的路径。其他php文件在哪里?@Felix指的是另一个所需文件的位置(路径)。只要试着用浏览器直接调用“services/Test.class.php”就行了。我正在用另一种方式使用Test.class.php,这没关系,所以我认为我的路径没有问题:)你也可以发布相关的php代码吗?