执行ajax脚本时,控制台中出现500服务器错误,我不知道为什么。如果我稍微更改代码来实现mysqli函数,并在我的本地机器上运行它们一切正常,但是一旦我尝试使用codeigniter,我就会得到500服务器错误。
这是我的代码:
<?php
class Phonecall extends CI_Controller {
public function index() {
/*$con = mysqli_connect('localhost','root','root','MYDB');
if (!$con) {
die ('Could not connect: ' . mysqli_error($con));
}*/
//$operatorId = $_SESSION['Oper']['OperatorID'];
//$sql = "SELECT phone_number FROM incoming_calls WHERE OperatorID='${operatorId}'";
//$result = mysqli_query($con,$sql);
$query = $this->db->query("SELECT phone_number FROM MYDB.incoming_calls");// WHERE OperatorID='${operatorId}'");
while ($row = $query->row_array()) {
$number = $row['phone_number'];
}
/*$sql = "SELECT Username, UserID, Name
FROM tblUsers
WHERE PhoneHome='999-999-9999' OR PhoneCell='999-999-9999' OR PhoneWork='999-999-9999'";
*/
$query = $this->db->query("SELECT Username, UserID, Name
FROM MYDB.tblUsers
WHERE PhoneHome='999-999-9999' OR PhoneCell='999-999-9999' OR PhoneWork='999-999-9999'");
while ($row = $query->row_array()) {
$userArray[] = array("name" => $row['Name'], "username" => $row['Username'], "user_id" => $row['UserID']);
}
if (!empty($userArray)) {
echo json_encode($userArray);
}
if (isset($_POST["drop"])) {
$query = $this->db->query("DELETE FROM MYDB.incoming_calls
WHERE phone_number = $number
LIMIT 1");
if (!$result) {
die ('Could not drop row: ');
}
}
$this->db->close();
}
}
?>
以下是检索信息的ajax调用:
var user = new Array();
var user_id = new Array();
var name = new Array();
$.get(baseURL + 'phonecall/index', function(data) {//where baseURL is defined
var loginInfo = jQuery.parseJSON(data);
for (var i = 0; i < loginInfo.length; ++i) {
name[i] = loginInfo[i].name;
user[i] = loginInfo[i].username;
user_id[i] = loginInfo[i].user_id;
}
}
有谁知道为什么会这样?