【发布时间】:2016-03-12 08:07:49
【问题描述】:
当我将javascript标签放在index.html文件中时,它运行良好,但当我将它放在静态目录中时,它不起作用,也没有错误。
views.py:
def index(request):
return render(request, 'index.html')
index.html:(在templates目录中)
{% load staticfiles %}
<script src={% static "/static/jquery.min.js" %}></script>
<script src={% static "/static/script.js" %} type="text/javascript"></script>
<div class="content" id="ajax">
{% include "svgmap.html" %}
</div>
selection.html:(在templates目录中)
<div style="width:600px;height:300px;border:1px solid red;margin-top:190px;margin-left:50px;">
</div>
并且在 svgmap.html(在templates 目录中)中,我已将onclick="loadDoc()" 添加到每个<path> 标记中。
script.js:(在app目录下,/map/static/)和javascript.min.js在同一个目录下。
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("ajax").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "/templates/selection", true);
xhttp.send();
}
</script>
【问题讨论】:
标签: javascript python django static