-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataHandler.js
More file actions
66 lines (49 loc) · 1.98 KB
/
dataHandler.js
File metadata and controls
66 lines (49 loc) · 1.98 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
function fetchAllData(){
var xhttp = new XMLHttpRequest();
var methParam = "functionSelector=getData";
xhttp.onreadystatechange = function(){
if (xhttp.readyState == 4 && xhttp.status == 200){
document.getElementById("post-list").innerHTML = xhttp.responseText;
}
};
xhttp.open("POST", "data-service.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(methParam);
}
function ajaxDataPost(){
var xhttp = new XMLHttpRequest();
var url ="data-service.php";
var name = document.getElementById("name").value;
var blogpost = document.getElementById("blogpost").value;
var functionSelect = "postData"
var varQuery = "functionSelector="+functionSelect+"&name="+name+"&blogpost="+blogpost;
xhttp.open("POST", url, false);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onreadystatechange = function() {
if(xhttp.readyState == 4 && xhttp.status == 200){
document.getElementById("status").innerHTML = xhttp.responseText;
}
}
xhttp.send(varQuery);
clearForm();
fetchAllData();
}
function ajaxDataDelete(indexToDelete){
var xhttp = new XMLHttpRequest();
var url= "data-service.php";
var functionToSelect = "deleteData";
var varMethQuery = "functionSelector="+functionToSelect+"&deleteIndex="+indexToDelete;
xhttp.open("POST", url, true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onreadystatechange = function() {
if(xhttp.readyState == 4 && xhttp.status == 200){
document.getElementById("status").innerHTML = xhttp.responseText;
}
}
xhttp.send(varMethQuery);
fetchAllData();
}
function clearForm(){
document.getElementById('name').value = "";
document.getElementById('blogpost').value = "";
}