Skip to content

Instantly share code, notes, and snippets.

@sbstp
Created October 27, 2013 04:34
Show Gist options
  • Save sbstp/7177998 to your computer and use it in GitHub Desktop.
Save sbstp/7177998 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Ajax / Exemple 1</title>
<meta charset="UTF-8">
</head>
<body>
<!-- Contrôles -->
Entrez un domaine ou une IP:<br>
<input id="text"><br>
Résultat:<br>
<input id="result"><br>
<button id="button">Go</button>
<!-- Inclure jquery -->
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<!-- Script qui fait les trucs -->
<script>
// raccourci à la fonction $.ready(fn) -> $(fn)
$(function () {
// ajouter l'évènement click sur le bouton
$('#button').click( function () {
// getJSON est un wrapper autour de $.ajax qui simplifie
// son utilisation et qui formatte le résultat en JSON.
// paramètre 1: string url,
// paramètre 2: object key/value,
// paramètre 3: function callback à appeler lorsque la
// requête est finie
$.getJSON('target.php', {
text: $('#entry').val()
}, function (data) {
// on place la valeur retournée par php dans le résultat
$('#result').val(data.res);
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment