1+ < html >
2+
3+ < head >
4+ < title > Home Page</ title >
5+ < meta content ="text/html;charset=utf-8 " http-equiv ="Content-Type ">
6+ < meta content ="utf-8 " http-equiv ="encoding ">
7+ < style >
8+ * , ::after , ::before {
9+ box-sizing : inherit;
10+ background-color : # ED5FCA ;
11+ color : rgb (8 , 8 , 71 );
12+ }
13+ .moby {
14+ padding : 2rem 1rem ;
15+ margin-bottom : 2rem ;
16+ border-radius : .3rem ;
17+ border-bottom : 0 ;
18+ text-align : center;
19+ align-content : center;
20+ align-items : center;
21+ padding : 4rem 2rem ;
22+ }
23+ .moby button {
24+ color : # fff ;
25+ background-color : # C568F0 ;
26+ border-color : # C568F0 ;
27+ padding : 5px ;
28+ border-radius : 5px ;
29+ margin : 5px ;
30+ }
31+ .moby .query {
32+ text-align : left;
33+ border : 3px dotted # e9ecef ;
34+ padding : 1.5rem 1.2rem ;
35+ max-width : 800px ;
36+ min-height : 200px ;
37+ margin-left : auto;
38+ margin-right : auto;
39+ border-radius : .3rem ;
40+ }
41+ .moby .query button : hover {
42+ cursor : pointer;
43+ background-color : # A639D8 ;
44+ }
45+
46+ .moby .query2 {
47+ text-align : left;
48+ border : 3px dotted # 124d88 ;
49+ padding : 1.5rem 1.2rem ;
50+ max-width : 800px ;
51+ min-height : 200px ;
52+ margin-left : auto;
53+ margin-right : auto;
54+ border-radius : .3rem ;
55+ }
56+ .moby .query2 button : hover {
57+ cursor : pointer;
58+ background-color : # 662186 ;
59+ }
60+ </ style >
61+ </ head >
62+ < body >
63+
64+ < div class ="moby ">
65+ < img src ="http://www.pngall.com/wp-content/uploads/2016/05/Kitten-Free-PNG-Image.png " />
66+
67+ < h1 > Hello there!</ h1 >
68+
69+ < p > I changed the colours and the picture!</ p >
70+
71+ < div class ="query ">
72+ < p > This is a test query. Click 'GET' or type 'another' and click 'GET'</ p >
73+ < div >
74+ < button type ="submit " onclick ="queryServer() "> GET</ button >
75+ < input id ="path " type ="text ">
76+ </ div >
77+ < h3 > And the response is:</ h3 >
78+ < div id ="response ">
79+
80+ < div class ="moby ">
81+ < div class ="query2 ">
82+ < p > This is the square root calculator</ p >
83+ < div >
84+ < button type ="submit " onclick ="queryServer2() "> CALCULATE</ button >
85+ < input id ="input " type ="number ">
86+ </ div >
87+ < h3 > And the answer is:</ h3 >
88+ < div id ="answer ">
89+
90+ </ div >
91+ </ div >
92+ </ div >
93+
94+ < script type ="text/javascript ">
95+ function queryServer ( ) {
96+ const Http = new XMLHttpRequest ( ) ;
97+ const path = document . getElementById ( 'path' ) . value ;
98+ const url = "/api/" ;
99+ Http . open ( "GET" , url + path ) ;
100+ Http . send ( ) ;
101+
102+ Http . onreadystatechange = ( e ) => {
103+ document . getElementById ( 'response' ) . innerHTML = Http . responseText ;
104+ }
105+ }
106+
107+ function queryServer2 ( ) {
108+ var xhr = new XMLHttpRequest ( ) ;
109+ const input = document . getElementById ( 'input' ) . value ;
110+ const url = "/api/square_root" ;
111+ xhr . open ( "POST" , url , true ) ;
112+ xhr . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ;
113+ xhr . send ( input ) ;
114+
115+ xhr . onreadystatechange = ( e ) => {
116+ document . getElementById ( 'answer' ) . innerHTML = xhr . responseText ;
117+ }
118+ }
119+ </ script >
120+
121+ </ body >
122+
123+ </ html >
0 commit comments