Bonjour,
Pour faire un petit test de l'utilisation ajax et récupération de réponse sous forme JSon, j'ai crée un petit bout de code à partir de l'exemple dispo sur le site.
J'ai ajouté une zone de saisie. Mon problème c'est que pour que ça marche, je doit saisir 2 fois
Merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Recherche Fickr </title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready( function () { $("#rechercheForm").submit( function() { var url = "http://api.flickr.com/services/feeds/photos_public.gne?tagmode=any&format=json&jsoncallback=?&tags=cat"+$("#tag").val(); $.getJSON(url, function(data){ $.each(data.items, function(i,item){ $("<img/>").attr("src", item.media.m).appendTo("#images"); if ( i == 3 ) return false; }); }); }); }); </script> </head> <body> <div id="container"> <div id="recherche"> <!-- bloc contenant le formulaire --> <form name="rechercheForm" id="rechercheForm" action="#"> <fieldset> <legend>Recherche</legend> <label for="tag">Tag :</label> <input type="text" name="tag" id="tag" /> <input type="submit" value="Recherche" class="bouton" /> </fieldset> </form> </div> <div id="contenu"> <fieldset id="images"> <legend>Images</legend> </fieldset> </div> </div> </body> </html>
Partager