2626 data: $ (' #form1' ).serialize (),
2727 dataType: " json" ,
2828 success : function (response ) {
29- // console.log('response');
3029 clearInputs ();
3130 Show ();
3231 // $( "#a" ).click();
3736 });
3837
3938 $ (' table' ).on (' click' , ' .update-button' , function () {
40- // alert('asssaaa');
4139 let rowEl = $ (this ).closest (' tr' );
4240 let id = rowEl .find (' .id' ).text ();
4341 let fullname = rowEl .find (' .fullname' ).val ();
5755
5856 });
5957 $ (' table' ).on (' click' , ' .delete-button' , function () {
60- // alert("DELETE");
6158 let rowEl = $ (this ).closest (' tr' );
6259 let id = rowEl .find (' .id' ).text ();
6360
7673 Show ();
7774 });
7875 function Show () {
79- // alert("Show");
8076 $ .ajax ({
8177 type: ' GET' ,
8278 url: ' /show' ,
8379 dataType: " json" ,
8480 success : function (response ) {
8581 console .log (response);
86- let tbodyEl = $ (' tbody' );
82+ // let tbodyEl = $('tbody');
83+ let tbodyEl = $ (" #myTable > tbody" )
8784
8885 tbodyEl .html (' ' );
8986
9087 response .forEach (function (product ) {
9188 tbodyEl .append (' \
9289 <tr>\
9390 <td class="id">' + product .unique_id + ' </td>\
94- <td><input type="text" class="fullname" value="' + product .fullname + ' "></td>\
95- <td><input type="text" class="username" value="' + product .username + ' "></td>\
96- <td><input type="text " class="age" value="' + product .age + ' "></td>\
91+ <td><input type="text" class="fullname form-control " value="' + product .fullname + ' "></td>\
92+ <td><input type="text" class="username form-control " value="' + product .username + ' "></td>\
93+ <td><input type="number " class="age form-control " value="' + product .age + ' "></td>\
9794 <td>\
98- <button class="update-button">UPDATE</button>\
99- <button class="delete-button">DELETE</button>\
95+ <button class="update-button btn btn-secondary ">UPDATE</button>\
96+ <button class="delete-button btn btn-danger ">DELETE</button>\
10097 </td>\
10198 </tr>\
10299 ' );
119116</head >
120117
121118<body >
122- <button id =" a" >Show</button >
119+ <button id =" a" class =" btn btn-primary" >Show</button >
120+ <br />
121+ <br />
123122 <form id =" form1" method =" POST" >
124- <label >UserName:</label ><input type =" text" name =" username" id =" username" required >
125- <br />
126- <label >Fullname:</label ><input type =" text" name =" fullname" id =" fullname" required >
127- <br />
128- <label >Age:</label ><input type =" Number" name =" age" id =" age" required >
123+ <table style =" margin-left :auto ; margin-right :auto ;" >
124+ <tr >
125+ <td ><label >UserName</label ></td >
126+ <td ><input class =" form-control" type =" text" name =" username" id =" username" required ></td >
127+ </tr >
128+ <tr >
129+ <td ><label >Fullname</label ></td >
130+ <td ><input class =" form-control" type =" text" name =" fullname" id =" fullname" required ></td >
131+ </tr >
132+ <tr >
133+ <td ><label >Age</label ></td >
134+ <td ><input class =" form-control" type =" Number" name =" age" id =" age" required ></td >
135+ </tr >
136+ </table >
129137 <br />
130- <button type =" Submit" id =" add" >Submit</button >
138+ <button type =" Submit" id =" add" class = " btn btn-success " >Submit</button >
131139 </form >
132- <div >
133- < table >
134- <thead >
135- <tr >
136- <th >ID</th >
137- <th >FullName</th >
138- <th >UserName</th >
139- <th >Age</th >
140- </ tr >
141- </thead >
142- < tbody >
143-
144- </ tbody >
145- </table >
146- </div >
140+ <br / >
141+ < table id = ' myTable ' style = " margin-left : auto ; margin-right : auto ; " >
142+ <thead >
143+ <tr >
144+ <th >ID</th >
145+ <th >FullName</th >
146+ <th >UserName</th >
147+ <th >Age</th >
148+ <th >Action</ th >
149+ </tr >
150+ </ thead >
151+ < tbody >
152+
153+ </tbody >
154+ </table >
147155</body >
148156
149157</html >
0 commit comments