javascript를 사용하여 HTML 페이지에서 몇 초마다 표의 내용을 새로 고치려고합니다. 내가 div, 내부 서버 오류를 새로 고치려고하면 500 오류가 계속. 누군가가 이것이 작동하지 않는 이유를 깨달을 수 있습니까? 나는 이것을 사용했다 : Refresh div using JQuery in Django while using the template system 내가했던 것을 참고로. 처음 새로 고침하지 못하면 페이지가 완벽하게로드됩니다. 여기 자바 스크립트를 사용하여 django에서 몇 초마다 특정 div를 새로 고침
내 코드입니다 :urls.py
url(r'^specialScoreboard/$', views.specialScoreboard.as_view(), name='specialScoreboard'),
url(r'^specialScoreboardDiv/$', views.specialScoreboardDiv , name='specialScoreboardDiv'),
views.py
class specialScoreboard(generic.ListView):
template_name = 'CTF/specialScoreboard.html'
context_object_name = 'teams'
@method_decorator(login_required)
@method_decorator(never_ever_cache)
def dispatch(self, request, *args, **kwargs):
if getAnyActiveGame and request.user.is_staff:
return super(specialScoreboard, self).dispatch(request, *args, **kwargs)
else:
return HttpResponseRedirect(reverse('CTF:no_active_game'))
def get_queryset(self):
"""
ordering teams by score
"""
game = getAnyActiveGame()
teams = get_teams_from_game(game)
return sorted(teams, key=lambda a: a.get_score(game), reverse=True)
def specialScoreboardDiv():
game = getAnyActiveGame()
teams = get_teams_from_game(game)
sortedList = sorted(teams, key=lambda a: a.get_score(game), reverse=True)
return render_to_response('CTF/specialscoreboardDiv.html' , {'sortedList' :sortedList})
scoreboardRefresh.js + scoreboardDiv.html
<script>
var scoreboardURL = '{% url '
CTF: specialScoreboardDiv ' %}';
function refresh() {
$.ajax({
url: scoreboardURL,
success: function(data) {
$('#scoreboardDiv').html(data);
}
});
};
$(document).ready(function($) {
refresh();
setInterval("refresh()", 3000);
})
< /script>
<div class="panel panel-info">
<div class="panel-heading">Scoreboard</div>
<div class="panel-body">
<div class="table-striped">
<table id="scoreboardDiv" class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Team Name</th>
<th>Score</th>
</tr>
</thead>
<tbody>
{% for team in teams %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{team.name}}</td>
<td>{{team|getScoreTeam}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
는, 여기의 사진입니다 : http://i.imgur.com/Yc11juA.png http://i.imgur.com/QluqZyc.png이 http://imgur.com/QluqZyc
오류는 무엇을 말하는가 :
난 당신 오류가보기 기능이 인수를 취함으로써 해결 될 것 같아? – arcegk
JS 시작 부분에 'scoreboardURL' 코드가 어떻게됩니까? 그것은 전혀 말이되지 않습니다. –
또한 들여 쓰기를 views.py에서 수정하십시오. 클래스의 일부이며 어떤 메소드가 아닌가? –