Guest User

Untitled

a guest
May 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. <div class="collapse navbar-collapse" id="navbarNavDropdown">
  2. <ul class="navbar-nav">
  3. <li class="nav-item dropdown">
  4. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  5. Dropdown link
  6. </a>
  7. <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
  8. <a class="dropdown-item" href="#" onclick="origin()">Action</a>
  9. <a class="dropdown-item" href="#" onclick="formOrigin()">Another action</a>
  10. </div>
  11. <div>
  12. <table class="table"></table>
  13. </div>
  14. <div>
  15. <form>
  16. <div class="form-group">
  17. <label for="name">Name</label>
  18. <input type="text" class="form-control" id="name" placeholder="Enter name">
  19. </div>
  20. <div class="form-group">
  21. <label for="city">City</label>
  22. <input type="text" class="form-control" id="city" placeholder="city">
  23. </div>
  24. <div class="form-group form-check">
  25. <input type="checkbox" class="form-check-input" id="add">
  26. <label class="form-check-label" for="add">Check</label>
  27. </div>
  28. <button type="submit" class="btn btn-primary">Submit</button>
  29. </form>
  30.  
  31. </div>
  32.  
  33. function origin() {
  34.  
  35. var url = "http://localhost:8000/api/v1/origin";
  36. petition.onreadystatechange = ResponseOrigin;
  37. petition.open("GET", url, true);
  38. petition.send();
  39. }
  40.  
  41. function ResponseOrigin(){
  42. var response;
  43. text="<tr><th>Identifier</th><th>Name</th><th>Numero</th><th>City</th></tr>";
  44. if (petition.readyState == 4)
  45. if (petition.status == 200) {
  46. responser = petition.responseText;
  47. var responseC = response.split("<");
  48. var responseV = responseC[0];
  49. var data = JSON.parse(responseV);
  50. for (var i = 0; i < data.length; i++) {
  51.  
  52. text += "<tr id =" + data[i].id + "><td>" + data[i].id + "</td><td id='name'>" + data[i].name + "</td><td>" +
  53. data[i].city + "</td>";
  54.  
  55. document.getElementById('table').innerHTML = text;
  56.  
  57. document.formOrigin.style.display="none";
  58. }
  59. else alert("Problem with URL");
  60. }
  61.  
  62. function formOrigin() {
  63.  
  64.  
  65. var url = "http://localhost:8000/api/v1/origin";
  66. petition.onreadystatechange = responseAddOrigin;
  67. petition.open("POST", url, true);
  68. petition.send(JSON.stringify({name: document.formOrigin.name.value,
  69. city: document.formOrigin.city.value}));
  70.  
  71. }
  72. function responseAddOrigen(){
  73.  
  74. var response;
  75. if (petition.readyState == 4)
  76. if (petition.status == 200) {
  77. response = petition.responseText;
  78. alert ("data recorded correctly");
  79. }
  80. else
  81. alert("Problem with URL");
  82. }
  83.  
  84. text += "<tr id =" + data[i].id + "><td>" + data[i].id + "</td><td id='name'>" + data[i].name + "</td><td>" +
  85. data[i].city + "</td> -->";<--
Add Comment
Please, Sign In to add comment