【发布时间】:2023-03-23 11:06:01
【问题描述】:
我有一个 php 页面 send.php,当我转到该页面时,它成功地回显了一个数组。但是,当我尝试在 index.php 上使用 ajax 来访问该页面时,没有响应。
这是我正在访问的页面 发送.php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$json = array(
"test" => null,
"success" => null,
"urls" => null,
);
$json = array("hi" => null, "success" => null);
$class = new test();
$json["success"] = true;
$json["hi"] = $class->_array;
echo json_encode($json);
class test{
public $_array = array();
public $urlPreArray;
public $sensoredArray;
function __construct(){
require_once('./mysqlDB.php'); //this causes nothing to be sent back
$cookieString = $_COOKIE['crUrl'];
$this->_array = explode(",", $cookieString);
}
}
这是我的索引页
<html>
<head>
<script src="jquery1.11.js"></script>
<meta charset="utf-8">
<script>
function load(){
$.get("./php/send.php",
{
action:"displayUrlsNotes"
},
function(data, status){
console.log(status);
console.log(data);
}, "json");
console.log("end");
}
</script>
</head>
<body>
<button onclick='load();'>Click Me</button>
</body>
</html>
如果我在浏览器中访问 send.php,它可以工作并打印数组,但是当我访问 index.php 并按下按钮时,ajax 请求已成功发出,但没有发回任何内容。
如果我注释掉 require_once('./mysqlDB.php'); 它确实有效在send.php中
我是在 php 中使用类的新手,我不确定我究竟需要什么来谷歌找到答案。
【问题讨论】:
-
您的 mysqlDB.php 在文件夹中还是在 index.php 路径中?
-
我有 index.php 和一个名为 php 的文件夹。 mysqlDB.php 和 send.php 在 php 文件夹中。我不相信这是一个目录问题,因为我将 mysqlDB.php 放在与 index.php 相同的文件夹中,但这并没有解决它。另外,如果这是问题所在,我认为在 send.php 时会出错
标签: php jquery ajax header require