-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyscript.js
More file actions
115 lines (92 loc) · 2.88 KB
/
myscript.js
File metadata and controls
115 lines (92 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Student arrayid
//var Students = [];
// Course array
//var Courses = [];
// Add Student
function addStudent() {
var first_NAME = $('#first_NAME').val();
var last_NAME = $('#last_NAME').val();
var Age = parseInt($('#Student_Age').val());
var course_Id =parseInt($('#course_ID').val());
var Student = {
first_NAME: first_NAME,
last_NAME: last_NAME,
age: Age,
course_Id: course_Id
};
$.ajax({
url: 'https://localhost:44347/api/Students/AddStudent',
type: 'POST',
data: JSON.stringify(Student),
contentType: 'application/json',
success: function() {
// Clear form
$('#StudentForm')[0].reset();
// Update Student List
fetchStudents();
}
});
}
// update Student
function updateStudent() {
var Student_ID = parseInt($('#ID').val());
var first_NAME = $('#Newfirst_NAME').val();
var last_NAME = $('#Newlast_NAME').val();
var Age = parseInt($('#NewAge').val());
var course_Id =parseInt($('#Newcourse_ID').val());
var Student = {
Student_ID: Student_ID,
first_NAME: first_NAME,
last_NAME: last_NAME,
Age: Age,
course_Id: course_Id
};
$.ajax({
url: 'https://localhost:44347/api/Students/UpdateStudentRecored',
type: 'PUT',
data: JSON.stringify(Student),
contentType: 'application/json',
success: function() {
// Clear form
$('#updateForm')[0].reset();
// Update Student List
fetchStudents();
}
});
}
// Fetch StudentsList
function fetchStudents() {
$.ajax({
url: 'https://localhost:44347/api/Students/GetAllStudents',
type: 'GET',
success: function(data) {
$('#StudentList').empty();
console.log(data);
data.forEach(function(Student) {
$('#StudentList').append('<li class="list-group-item">' + Student.student_Id + ', '+ Student.first_NAME + ', ' + Student.last_NAME + ', ' + Student.age + ', '+Student.course_Name+'</li>');
});
}
});
}
// Initial fetch
$(document).ready(function() {
fetchStudents();
// Students_Age_Above_20();
});
// Delete Student
function DeleteStudent() {
var Student_id = parseInt($('#Student_id').val());
$.ajax({
url: 'https://localhost:44347/api/Students/DeleteStudent' ,
type: 'POST',
// data: JSON.stringify(Student_id),
data: JSON.stringify(Student_id),
contentType: 'application/json',
success: function() {
// Clear form
$('#DeleteForm')[0].reset();
// Update Student List
fetchStudents();
}
});
}