Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script>
  4. function showList(str) {
  5. //console.log(str);
  6. if (str=="") {
  7. document.getElementById("txtHint").innerHTML="";
  8. return;
  9. }
  10. if (window.XMLHttpRequest) {
  11. // code for IE7+, Firefox, Chrome, Opera, Safari
  12. xmlhttp=new XMLHttpRequest();
  13. } else { // code for IE6, IE5
  14. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  15. }
  16. xmlhttp.onreadystatechange=function() {
  17. if (this.readyState==4 && this.status==200) {
  18. //alert(this.responseText); //importante per fare passo per passo
  19. if(str.endsWith("actor")){ //se l'indirizzo finisce con actor
  20.  
  21. visualJsonAttore(this.responseText);
  22. }
  23. }
  24. }
  25.  
  26. xmlhttp.open("GET",str,true); //da qua decido get,post...https://www.w3schools.com/xml/dom_httprequest.asp
  27. xmlhttp.send();
  28. }
  29.  
  30. function visualJsonAttore(json){
  31. var obj = JSON.parse(json);
  32. var table='<table border="1" ><tr><td>Id</td><td>nome</td><td>cognome</td><td>last update</td></tr>';
  33. for (i = 0; i <obj.length; i++) {
  34. table += "<tr><td>" + obj[i].actor_id + "</td><td>" +
  35. obj[i].first_name +"</td><td>" +
  36. obj[i].last_name +"</td><td>"+ obj[i].last_update +"</td></tr>";
  37. }
  38. table+="</table>";
  39.  
  40. document.getElementById("risultato").innerHTML = table;
  41. }
  42.  
  43.  
  44. </script>
  45. </head>
  46. <body>
  47. <center>
  48. <form>
  49. <select name="lista" onchange="showList(this.value)">
  50. <option value="">Seleziona un valore:</option>
  51. <option value="http://localhost:8000/FrameworkFlight/actor">Attori</option>
  52. </select>
  53. </form>
  54. <div id="risultato"><b>qui i risultati</b></div>
  55. </center>
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement