我有一个php页面,send.php在我转到该页面时成功回显了一个数组。但是,当我尝试在index.php上使用ajax访问该页面时,没有任何响应。
我正在访问的页面send.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中使用类的新手,并且不确定要在Google上找到答案的确切条件。
我想到了。问题是我的mysqlDB.php页面上有html代码。感谢您告诉我调查文件结构。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句