1
1

index.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <html>
  2. <head>
  3. <style>
  4. body {
  5. width:80vw;
  6. margin-left:auto;
  7. margin-right:auto;
  8. font-family:sans-serif;
  9. }
  10. #output {white-space:pre;}
  11. #output>div {margin-bottom:20px;}
  12. section {background-color:#e46920;padding:15px;margin-top:40px;}
  13. section:first-of-type>div {
  14. display:inline-block;
  15. padding:20px;
  16. margin-right:20px;
  17. vertical-align:middle;
  18. background-color: #e46920;
  19. box-shadow: 0 0 30px #71340f;
  20. }
  21. h1,h2,h3 {color:#bde420;}
  22. h1 {font-size:50px;}
  23. h3 {font-size:30px;}
  24. button {
  25. padding:10px;
  26. border-radius:10px;
  27. border:none;
  28. background-color:white;
  29. font-weight:bold;
  30. }
  31. textarea {
  32. height:100px;
  33. width:300px;
  34. display:block;
  35. margin-bottom:20px;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <h1>my first frontend</h1>
  41. <section>
  42. <h3>send data to the server</h3>
  43. <div>
  44. <button id="request1">meow</button>
  45. <br /><br /><br />
  46. <button id="request2">random data</button>
  47. </div>
  48. <div>
  49. <textarea id="userInput"></textarea>
  50. <button id="request3">submit</button>
  51. </div>
  52. </section>
  53. <section>
  54. <h3>server's response</h3>
  55. <!--<img id="catOutput" src="">-->
  56. <div id="output"></div>
  57. </section>
  58. </body>
  59. <script type="text/javascript" src="jquery.js"></script>
  60. <script>
  61. // when a button is clicked, send data to the server
  62. $("button").click(function()
  63. {
  64. // onscreen log - historical requests and responses
  65. // if the meow button is clicked, send the string "meow" to the server
  66. if($(this).attr("id") === "request1")
  67. {var data = "meow";}
  68. // if the random button is clicked, come up with a random string of random length to send
  69. else if($(this).attr("id") === "request2")
  70. {
  71. var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,";\/?<>';
  72. var cl = characters.length;
  73. var stringLength = Math.floor(Math.random()*300);
  74. var data = "";
  75. for(var i=0;i<stringLength;i++)
  76. {
  77. data += characters[Math.floor(Math.random()*cl)];
  78. }
  79. }
  80. // if the text box button is clicked, send the content of the text box
  81. else if($(this).attr("id") === "request3")
  82. {var data = $("#userInput").val();}
  83. // send the data to the server and display the response
  84. $.ajax({
  85. url:"mmcgo.com",
  86. type:"post",
  87. data:{},
  88. success:function(returnData)
  89. {
  90. returnData = "server says yay!";
  91. var temp = $("<div></div>");
  92. temp.append("<div>request: "+data+"</div>")
  93. temp.append("<div>response: "+returnData+"</div>")
  94. $("#output").prepend(temp);
  95. //var catWidth = Math.floor(Math.random()*300);
  96. //var catHeight = Math.floor(Math.random()*300);
  97. //$("#catOutput").attr("src","http://placekitten.com/"+catWidth+"/"+catHeight);
  98. }
  99. });
  100. });
  101. </script>
  102. </html>