0
def post_list(request):
if request.is_ajax():
posts = Post.objects.filter(user_id=1)
else:
posts = Post.objects.filter(user_id=3)
post_list = posts[:20]
return render(request, '...html', {'post_list': post_list})
這裏是腳本;腳本的提醒工作,但post_list不變通過jquery在模板中更改數據
$(document).ready(function() {
$('#some').change(function() {
var some= $('#some').val();
$.ajax({
url: '',
type: 'GET',
data: {
'user_id': some,
},
datatype: 'json',
success: function (data) {
alert('work');
},
error: function (jqXHR, textStatus, errorThrown) {
alert("don't work");
}
});
});
url(r'^$', post_list, name='post_list'),
你必須從回調數據插入到您的html模板。你的類型也是GET而不是POST ... – Jingo