@@ -5,35 +5,59 @@ $(document).ready(function() {
5
5
$ . ajax ( {
6
6
url : '/EmployeeList' ,
7
7
type : 'POST' ,
8
+ contentType : 'application/Json' ,
8
9
data : JSON . stringify ( {
9
10
"name" : $ ( '#name' ) . val ( ) ,
10
11
"job" : $ ( '#job' ) . val ( )
11
12
} ) ,
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
+
16
22
} ) ;
17
23
18
24
$ ( function ( ) {
19
25
updateTable ( ) ;
20
26
} ) ;
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
+ } ;
21
47
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
+ }
37
59
} ) ;
60
+
38
61
} ;
39
- } ) ;
62
+
63
+ } ;
0 commit comments