@@ -5,35 +5,59 @@ $(document).ready(function() {
55 $ . ajax ( {
66 url : '/EmployeeList' ,
77 type : 'POST' ,
8+ contentType : 'application/Json' ,
89 data : JSON . stringify ( {
910 "name" : $ ( '#name' ) . val ( ) ,
1011 "job" : $ ( '#job' ) . val ( )
1112 } ) ,
12- processData : false ,
13- contentType : "application/json"
14- } )
15- updateTable ( )
13+ success : function ( data , textStatus , jQxhr ) {
14+ updateTable ( ) ;
15+ $ ( '#newEmployee' ) . trigger ( 'reset' ) ;
16+ } ,
17+ error : function ( xhr , textStatus , errorThrown ) {
18+ console . log ( textStatus ) ;
19+ }
20+ } ) ;
21+
1622 } ) ;
1723
1824 $ ( function ( ) {
1925 updateTable ( ) ;
2026 } ) ;
27+ } ) ;
28+
29+ function updateTable ( ) {
30+ $ . get ( "/EmployeeList" , function ( data ) {
31+ $ ( '#employeeTable > tbody' ) . empty ( ) ;
32+ var table_data ;
33+ $ . each ( data , function ( i , employee ) {
34+ table_data += "<tr>" +
35+ "<td ><form>" + employee . id + "</td>" +
36+ "<td >" + employee . name + "</td>" +
37+ "<td>" + employee . job + "</td>" +
38+ "<td>" + employee . salary + "</td>" +
39+ "<td>" +
40+ "<button type=submit>Modificar</button>" +
41+ "<button type=submit onclick='deleteEmploye(" + employee . id + ")'>Eliminar</button>" +
42+ "<form></td>"
43+ } ) ;
44+ $ ( '#employeeTable > tbody' ) . append ( table_data ) ;
45+ } ) ;
46+ } ;
2147
22- function updateTable ( ) {
23- $ . get ( "/EmployeeList" , function ( data ) {
24- $ ( '#employeeTable > tbody' ) . empty ( )
25- $ . each ( data , function ( i , employee ) {
26- var tblRow = "<tr>" +
27- "<td>" + employee . id + "</td>" +
28- "<td>" + employee . name + "</td>" +
29- "<td>" + employee . job + "</td>" +
30- "<td>" + employee . salary + "</td>" +
31- "<td>" +
32- "<button type=submit>Modificar</button>" +
33- "<button type=submit>Eliminar</button>" +
34- "</td>"
35- $ ( tblRow ) . appendTo ( "#employeeTable tbody" ) ;
36- } ) ;
48+ function deleteEmploye ( id ) {
49+ if ( confirm ( "Desitja eliminar a l'Empleat?" ) ) {
50+ $ . ajax ( {
51+ type : "DELETE" ,
52+ url : "/EmployeeList/" + id ,
53+ success : function ( data , textStatus , jQxhr ) {
54+ updateTable ( ) ;
55+ } ,
56+ error : function ( xhr , textStatus , errorThrown ) {
57+ console . log ( textStatus ) ;
58+ }
3759 } ) ;
60+
3861 } ;
39- } ) ;
62+
63+ } ;
0 commit comments