PHP를 통해 mysql 데이터베이스에 최고 기록을 저장하고 있습니다. 점수를 내 앱으로 보내야하지만 작동하지 않습니다.AJAX를 통해 MySQL/PHP에 jQuery
<?php
$server = "...";
$user = "...";
$pass = "...";
$bd = "...";
$conexion = mysqli_connect($server, $user, $pass,$bd)
or die("Ha sucedido un error inexperado en la conexion de la base de datos");
$sql = 'SELECT * FROM table_one ORDER BY score DESC LIMIT 10';
if(!$result = mysqli_query($conexion, $sql)) die();
$scores = array();
while($row = mysqli_fetch_array($result))
{
$name=$row['name'];
$score=$row['score'];
$scores[] = array('name'=> $name, 'score'=> $score);
}
$close = mysqli_close($conexion)
or die("Ha sucedido un error inexperado en la desconexion de la base de datos");
$json_string = json_encode($scores);
header('Content-Type: application/json');
echo $json_string;
?>
JQUERY
$.ajax({
method: 'GET',
url: 'score2.php',
dataType: 'json',
success: function(result) {
var data = jQuery.parseJSON(result);
console.log(data);
}
도움하십시오
이것은 내가 지금 여기에 ... PHP와 JSON 함께 일하고 있어요 처음으로 내 코드
PHP이다?
당신이 생각하는 부분은 작동하지 않습니다.? – Saif
PHP에서는'header ('Content-Type : application/json');'줄이 필요하지 않으므로 jQuery에서 결과를 구문 분석 할 필요가 없습니다. dataType을 JSON으로 설정하면 jQuery가 자동으로 결과를 파싱합니다. – Styphon
결과의 상태는 어떻습니까? 200 !! 아약스 호출의 응답은 무엇입니까? – Moussawi7