我发现了一些类似的问题,但没有解决方案可以解决这个问题。
function loadProject(id) {
$.ajax({
url: 'loadDrumsetData.php',
type: 'GET',
data: {
i: id
},
dataType: 'JSON',
success: function (e) {
pushLoadedData(e.bank); //create the JavaScript array
},
error: function (request, textStatus, errorThrown) {
console.log(request, textStatus, errorThrown);
}
});
}
我尝试从中获取数组结果loadDrumsetData.php
。在我的本地 apache 上它工作正常。但是在我的网络服务器(apache)上,我得到了这个解析器错误:
SyntaxError: JSON.parse: unexpected end of data
loadDrumsetData.php:
<?php
header('Content-type: application/json; charset=UTF-8');
error_reporting(-1);
$i=$_GET["i"];
$con=mysqli_connect("localhost","userxxx","xxxxx","drumpcdata");
if (mysqli_connect_errno())
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con," SELECT * FROM `session_".$i."` ORDER BY `pID` ASC ");
$soundArray = array();
$bankArray = array();
while($row = mysqli_fetch_array($result))
{
$pid = $row['pID'];
$r = $row['Row'];
$sound = $row['Sound'];
$number = $row['Number'];
$x = $row['X'];
$y = $row['Y'];
$w = $row['W'];
$h = $row['H'];
$spr = $row['Sprite'];
$pressed = $row['Pressed'];
$bankArray = [];
array_push($soundArray, [$pid, $r, $sound ,$number,$x,$y,$w,$h,$spr, $pressed]);
array_push($bankArray, $soundArray);
}
mysqli_close($con);
$encoded = json_encode(array("bank" => $bankArray));
echo $encoded;
?>
我将不胜感激有关此主题的任何帮助。任何想法是什么问题?