-
-
Save Denkong/d6bd9124bb0c2d51b9d05feec6c807a8 to your computer and use it in GitHub Desktop.
AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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