forked from jazzband/django-debug-toolbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
47 lines (47 loc) · 1.61 KB
/
index.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
{% load cache %}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Index of Tests</title>
</head>
<body>
<h1>Index of Tests</h1>
{% cache 10 index_cache %}
<ul>
<li><a href="/jquery/">jQuery 3.3.1</a></li>
<li><a href="/mootools/">MooTools 1.6.0</a></li>
<li><a href="/prototype/">Prototype 1.7.3.0</a></li>
</ul>
<p><a href="/admin/">Django Admin</a></p>
{% endcache %}
<p>
<span>Value </span>
<span id="session-value">{{ request.session.value|default:0 }}</span>
<button id="incrementFetch" data-url="{% url 'ajax_increment' %}" type="button">Increment via fetch</button>
<button id="incrementXHR" data-url="{% url 'ajax_increment' %}" type="button">Increment via XHR</button>
</p>
<script>
const incrementFetch = document.querySelector("#incrementFetch");
const incrementXHR = document.querySelector("#incrementXHR");
const value = document.querySelector("#session-value");
incrementFetch.addEventListener("click", function () {
fetch(incrementFetch.dataset.url).then( function (response) {
response.json().then(function(data) {
value.innerHTML = data.value;
});
});
});
incrementXHR.addEventListener("click", function () {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
value.innerHTML = JSON.parse(xhr.response).value;
}
}
xhr.open('GET', incrementXHR.dataset.url, true);
xhr.send('');
});
</script>
</body>
</html>