Ajax在Javascript中产生错误的输出

我无法理解为什么我的ajax输出错误的代码。 它输出的css负载,我相信它来自我的’MySQLDao.php’文件,但我不确定。 代码如下。 有人说这是因为“data:{action:’getResults’}”行被忽略了,但我不知道如何制作它所以它不会被忽略。 任何帮助表示赞赏。 谢谢!

我的Javascript代码的一部分:

function callPHP() { $.ajax ({ type: "GET", datatype: "application/json", url: "MySQLDao.php", data: { action : 'getResults' }, success: function(output) { alert(output); } }); } callPHP(); 

我的PHP文件:

 dbhost = Conn::$dbhost; $this->dbuser = Conn::$dbuser; $this->dbpass = Conn::$dbpass; $this->dbname = Conn::$dbname; } //Attempt a connection to the database public function openConnection() { //Try and connect to the database $this->mysqli = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); //If the connection threw an error, report it if (mysqli_connect_errno()) { return false; } else { return true; } } //Get method for retrieving the database conection public function getConnection() { return $this->mysqli; } //Close the connection to the database public function closeConnection() { //If there is a connection to the database then close it if ($this->mysqli != null) $this->mysqli->close(); } //-----------------------------------QUERY METHODS------------------------------------- public function generateRoomID() { $sql = "INSERT INTO room (room_id) VALUES (null);"; $result = $this->mysqli->query($sql); if ($result == true) { $toReturn["status"] = true; $toReturn["roomID"] = $this->mysqli->insert_id; return $toReturn; } else { $toReturn["status"] = false; $toReturn["message"] = mysql_error($this->mysqli); return $toReturn; } } public function saveRoom($data) { $roomID = $data[0]; $roomDescription = $data[1]; $columns = $data[2]; $rows = $data[3]; $this->mysqli->autocommit(FALSE); $this->mysqli->query("UPDATE room SET room_description='".$roomDescription."' WHERE room_id='".$roomID."';"); for ($i = 0; $i<count($columns); $i++) { for ($j = 1; $jmysqli->query("INSERT INTO shelf (shelf_label) VALUES ('".$currentLabel."');"); $shelfID = $this->mysqli->insert_id; $this->mysqli->query("INSERT INTO room_shelf (room_id, shelf_id) VALUES ('".$roomID."','".$shelfID."');"); } } if ($this->mysqli->commit()) { $toReturn["status"] = true; $toReturn["message"] = "Room Created"; return $toReturn; } else { $this->mysqli->rollback(); $toReturn["status"] = false; $toReturn["message"] = "SQL Error"; return $toReturn; } } public function updateShelf($data) { $shelfID = $data[0]; $itemName = $data[1]; } public function getRoomDetails($data) { $roomID = $data[0]; $sql = "SELECT room.room_description, shelf.shelf_label, shelf.shelf_id FROM room INNER JOIN room_shelf ON room.room_id=room_shelf.room_id INNER JOIN shelf ON shelf.shelf_id=room_shelf.shelf_id WHERE room.room_id='".$roomID."';"; $result = $this->mysqli->query($sql); if (mysqli_num_rows($result) > 0) { $toReturn["status"] = true; $toReturn["message"] = "Room Found"; $toReturn["room_description"] = $row['room_description']; $shelves = []; foreach ($result as $row) { $currentShelf["shelf_label"] = $row['shelf_label']; $currentShelf["shelf_id"] = $row['shelf_id']; array_push($shelves, $currentShelf); } $toReturn["shelves"] = $shelves; return $toReturn; } else { $toReturn["status"] = false; $toReturn["title"] = "Error"; $toReturn["message"] = "Room Not Found"; return $toReturn; } } public function getResults($data) { $sql = "SELECT room.room_description FROM room WHERE room.room_id = 1"; $result = $this->mysqli->query($sql); echo json_encode($result); } } $daoObj = new MySQLDao(); $daoObj->getResults(); ?> 

我的康恩class:

  

我的基础类:

 openConnection() == false) { $returnValue["status"] = false; $returnValue["title"] = "Error"; $returnValue["message"] = "Connection Could Not Be Established Between Server And Database"; echo json_encode($returnValue); } else { //Decodes data, dont change $body = json_decode($raw_post_data, true); $recieved = $body["data"]; //Gets the result of a query //$result = $dao->MySQLDaoMethodName(parameters); //Return the result of the query echo json_encode($result); } $dao->closeConnection(); return; } ?>