Ajax MySQL "Unexpected token <"

Ajax MySQL "Unexpected token <"

我想做简单的事情,从 MySQL 数据库中获取 table。 早些时候我没有 MySQLi 代码,简单 MySQL 并且它正在工作。现在,更改为 MySQLi 后出现错误:

Uncaught SyntaxError: Unexpected token <

我有这个代码:

AJAX:

("#load-all").click(function(){
    $.ajax({   
        type: "GET",
        url: "akceptAPI.php",             
        dataType: "text",             
        success: function(response){ 
                var data = jQuery.parseJSON(response);
                datatable = data;
                generateTable(data);                  
                bindTr();
            },
        error: function(xhr, ajaxOptions, thrownError){
            alert(thrownError);
        }
    });
});

AkceptAPI.php(请求)

<?php
//include db configuration file
include_once("connect.php");

//MySQLi query
$results = $mysqli->query("SELECT * FROM oczekujace");
//get all records from add_delete_record table
$array = array();
$tempArray = array();
while($row = $results->mysql_fetch_row())
{
    $tempArray = $row;
 // $array[]= array("ID"=>$row[0],"Nazwa"=>$row[1],"Autor"=>$row[2],"Cena"=>$row[3],"Opis"=>$row[4],"JSON_DATA"=>$row[5]);
    array_push($array,$tempArray)
}

echo json_encode($array);
//close db connection
$mysqli->close();
?>

connect.php

<?php

$username = "root"; //mysql username
$password = ""; //mysql password
$hostname = "localhost"; //hostname
$databasename = 'obrazypol'; //databasename

//connect to database
$mysqli = new mysqli($hostname, $username, $password, $databasename);

?>

使用

while($row = $results->fetch_row())

而不是

while($row = $results->mysql_fetch_row())

存在语法错误。 array_push 函数后缺少分号。

$mysqli = new mysqli($hostname, $username, $password, $databasename);
//MySQLi query
$results = $mysqli->query("SELECT * FROM category");
//get all records from add_delete_record table
$array = array();
$tempArray = array();
while($row = $results->fetch_row())
{
   $tempArray = $row;
    // $array[]=       array("ID"=>$row[0],"Nazwa"=>$row[1],"Autor"=>$row[2],"Cena"=>$row[3],"Opis"=>$row[4],"JSON_DATA"=>$row[5]);
   array_push($array,$tempArray);
}

echo json_encode($array);
//close db connection
$mysqli->close();