Приветствую всех, проверял сайт с базой данных на Open Server, все работает ни каких ошибок, перенес на хостинг и появилось это : Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Object.vesShiny [as success] (scripts.min.js:43)
at u (scripts.min.js:2)
at Object.fireWith [as resolveWith] (scripts.min.js:2)
at k (scripts.min.js:2)
at XMLHttpRequest.<anonymous> (scripts.min.js:2)
Запрос к базе:
$servername = "localhost";
$username = "*****";
$password = "******";
$dbname = "*******";
function connect(){
$conn = mysqli_connect("localhost", "********", "*******", "*********");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
return $conn;
}
function init() {
$conn = connect();
$sql = "SELECT * FROM shiny";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$out = array();
while($row = mysqli_fetch_assoc($result)) {
$out[$row["id"]] = $row;
}
echo json_encode($out);
} else {
echo "0";
}
mysqli_close($conn);
}
Вывод на станицу:
function init() {
$.post(
"core.php",
{
"action" : "init"
},
vesShiny
);
}
function vesShiny(data) {
data = JSON.parse(data);
var out = '';
for (var key in data){
out+='<div class="cart ' + data[key] ['season'] + ' ' + data[key] ['ship'] + '" data-brend="' + data[key] ['brend'] + '" data-width="' + data[key] ['width'] + '" data-height="' + data[key] ['height'] + '" data-diametr="' + data[key] ['diametr'] + '" data-weight="' + data[key] ['weight'] + '" id="cart">';
out+='<img src="' + data[key].image +'">';
out+='<p class="brend"><b>' + data[key] ['brend'] + '</b></p>';
out+='<p class="name"><b>' + data[key] ['name'] + '</b></p>';
out+='<p class="width"><b>Ширина: ' + data[key] ['width'] + '</span></b></p>';
out+='<p class="height"><b>Высота: ' + data[key] ['height'] + '</span></b></p>';
out+='<p class="diametr"><b>Диаметр: ' + data[key] ['diametr'] + '</span></b></p>';
out+='<p class="season"><b>Сезон: ' + data[key] ['season'] + '</span></b></p>';
out+='<p class="weight"><b>Вес: ' + data[key] ['weight'] + ' кг.</span></b></p>';
out+='</div>';
}
$('.carts').html(out);
}
$(document).ready(function() {
init();
});