-
Notifications
You must be signed in to change notification settings - Fork 0
/
TODO-AJAJX-ALL.html
101 lines (85 loc) · 2.54 KB
/
TODO-AJAJX-ALL.html
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
<html>
<head>
<script type="text/javascript">
function change()
{
xmlhttp= new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
document.getElementById("mydiv").innerHTML="";
if(this.readyState==4 && this.status==200)
{
var x=JSON.parse(xmlhttp.responseText);
for(var obj in x)
{
ptag=document.createElement("p")
ptag.innerHTML+=x[obj].id+" "+x[obj].user+" "+" "+x[obj].phonenumber+" ";
var div=document.getElementById("mydiv");
div.appendChild(ptag);
b=document.createElement("BUTTON");
b.setAttribute("onClick","todo(this.id);");
b.setAttribute("id",x[obj].id);
t=document.createTextNode("delete");
b.appendChild(t);
ptag.appendChild(b);
}
}
}
xmlhttp.open("GET",'http://127.0.0.1:8000/api/v1/details/',true);
xmlhttp.send();
}
function todo(i)
{
location.reload();
Delete(i);
}
function Delete(i)
{
console.log(i);
xmlhttp= new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
document.getElementById("delete").innerHTML="";
if(this.readyState==4 && this.status==200)
{
document.getElementById("delete").innerHTML=JSON.parse(xmlhttp.responseText);
}
}
xmlhttp.open("DELETE",'http://127.0.0.1:8000/api/v1/details/'+i,true);
xmlhttp.send();
}
function post()
{
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
// document.getElementById("done").innerHTML=xmlhttp.reponseText;
}
value={
id:1,
user:document.getElementById("user").value,
phonenumber:document.getElementById("phonenumber").value
},
//xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.open("POST",'http://127.0.0.1:8000/api/v1/details/',true);
xmlhttp.setRequestHeader("Content-type","application/json");
xmlhttp.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
xmlhttp.send(JSON.stringify(value));
console.log(JSON.stringify(value));
}
function todo1()
{
post();
location.reload();
}
</script>
</head>
<body onload="change()">
<p> user <input type="text" id="user" placeholder="enter your name"> </p>
<p> phonenumber <input type="number" id="phonenumber" placeholder="enter the phonenumber"> </p>
<button onclick="todo1()"> submit </button>
<br>
<br>
<div id="mydiv"> Null Data </div>
</body>
</html>