Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5.  
  6. <h3> City Data</h3>
  7.  
  8. City Name:
  9. <input type="text" name="cityName" id="cityName">
  10. <br><br>
  11. Description: <textarea rows="4" cols="50" name="cityDescription" id="cityDescription" form="cityForm"></textarea>
  12. <br><br>
  13. <input type="submit" value="Submit" id="sayButton" class="buttons">
  14.  
  15.  
  16. <script src="city-scripts.js"></script>
  17. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
  18.  
  19. </body>
  20. </html>
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. -----javascript---------
  28.  
  29. var API_ENDPOINT = "YOUR-API-GATEWAY-HERE"
  30.  
  31. document.getElementById("sayButton").onclick = function(){
  32.  
  33. var inputData = {
  34. "cityName": $('#cityName').val(),
  35. "cityDescription" : $('#cityDescription').val()
  36. };
  37.  
  38. alert("cityName:" + inputData.cityName);
  39. alert("cityDescription:" + inputData.cityDescription);
  40.  
  41. $.ajax({
  42. url: API_ENDPOINT,
  43. type: 'POST',
  44. data: JSON.stringify(inputData) ,
  45. contentType: 'application/json; charset=utf-8',
  46. success: function (response) {
  47. document.getElementById("postIDreturned").textContent="Post ID: " + response;
  48. },
  49. error: function () {
  50. alert("error");
  51. }
  52. });
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement