File: ajax.html

package info (click to toggle)
python-django-debug-toolbar 1%3A5.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,984 kB
  • sloc: python: 6,880; javascript: 631; makefile: 62; sh: 16
file content (22 lines) | stat: -rw-r--r-- 576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{% extends "base.html" %}

{% block content %}
  <div id="click_for_ajax">click for ajax</div>

  <script>

  let click_for_ajax = document.getElementById("click_for_ajax");
  function send_ajax() {
    let xhr = new XMLHttpRequest();
    let url = '/json_view/';
    xhr.open("GET", url, true);
    xhr.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            console.log(this.responseText);
        }
    }
    xhr.send();
  }
  document.addEventListener("click", (event) => {send_ajax()});
  </script>
{% endblock content %}