zipzippy

Search JSON AJAX

Dec 8th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Naslov</title>
  4. <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  5. <style type="text/css">
  6. #content{
  7. width: 500px;
  8. padding: 5px;
  9. margin: 10px;
  10. display: none;
  11. }
  12. #contentList{
  13. list-style-type: none;
  14. }
  15. #contentList li{
  16. background: lightgreen;
  17. }
  18. </style>
  19. <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  20. <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  21. <script type="text/javascript">
  22.  
  23. </script>
  24.  
  25. </head>
  26. <body>
  27. <h3>Something like google:</h3>
  28.  
  29.  
  30. <input type="text" id="searchBox">
  31. <button type="button" id="searchButton">Search</button>
  32. <div id="content">
  33. <ul id="contentList">
  34.  
  35. </ul>
  36. </div>
  37. <script type="text/javascript">
  38. $("#contentList li").selectable();
  39. $("#searchButton").click(function(){
  40. var term = $("#searchBox").val();
  41. $("#content").show();
  42. $.ajax({
  43. url: "http://www.flickr.com/services/feeds/photos_public.gne?tags=" + term + "&format=json#",
  44. dataType: "jsonp",
  45. jsonp: "jsoncallback",
  46. success:function(data){
  47.  
  48. $("#contentList").html("");
  49. var item = data.items;
  50. $.each(item, function(index, object) {
  51. $("#contentList").append("<li style='border: solid 1px black; margin-bottom: 20px' title1='" + object.title + "'> <a style='display:block' href='" + object.link + "'>" + object.title + " </br> <img src='" + object.media.m + "'> </br>" + object.published + "</br> </li>");
  52. });
  53. }
  54. });
  55. });
  56. </script>
  57. </body>
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment