Джанго Аякс не работает

-1

index.html:

<head>

{% load staticfiles %}
<script src={% static "/static/jquery.min.js" %}></script>

<script>
function loadDoc() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("demo").innerHTML = xhttp.responseText;
        }
    };
xhttp.open("GET", "text.html", true);
xhttp.send();
}
</script>

</head>

<p id="ajax">hello wordl</p>
<button type="button" onclick="loadDoc()">Change Content</button>

и text.html:

<p>goodbye</p>

Оба файла находятся в одном каталоге (каталог шаблонов). Ничего не происходит, нажимая кнопку.

Теги:
static

1 ответ

0

Я нашел ответ. Я добавил:

def text(request):
    return render(request, 'text.html')

в views.py, и это:

url(r'^text', text),

в urls.py.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню