gpt4 book ai didi

php - Ajax MySQL "Unexpected token <"

转载 作者:行者123 更新时间:2023-11-29 06:30:13 25 4
gpt4 key购买 nike

我想做简单的事情,从 MySQL 数据库中获取表。早些时候我没有 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();
?>

连接.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);

?>

最佳答案

语法错误。 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();

关于php - Ajax MySQL "Unexpected token <",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28450620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com