Skip to content

Instantly share code, notes, and snippets.

@Denkong
Last active August 28, 2018 08:41
Show Gist options
  • Select an option

  • Save Denkong/d6bd9124bb0c2d51b9d05feec6c807a8 to your computer and use it in GitHub Desktop.

Select an option

Save Denkong/d6bd9124bb0c2d51b9d05feec6c807a8 to your computer and use it in GitHub Desktop.
AJAX
PHP:
<?
try {
$dbh = new PDO('mysql:dbname=name;host=host', 'login', 'password');
} catch (PDOException $e) {
die($e->getMessage());
}
$MTS = $dbh->prepare('SELECT * FROM test ORDER BY score DESC LIMIT 10' );
$MTS->execute();
$results= $MTS->fetchAll();
echo json_encode($results);
?>
JS:
function getDate(){
$.ajax({
url:"show_result.php",
//dataType: 'json',
type:"GET",
data:({
name:$("#name").val(),
time:player.timerSec,
score:player.score
})
})
.done(function(data){
var obj = jQuery.parseJSON( data);
console.log(data)
for (var i = 0; i < obj.length; i++) {
obj[i]['name']
obj[i]['score']
}
} );//функция успешна обработала все данные, пришел ответ)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment