完全不清楚404 Ajax错误。
var int_page_number = 2;
$.ajax({
type:'GET',
url: '/loadmore/',
data: { 'page_number' : int_page_number},
dataType: 'json',
success: function (data) {
alert(data);
}
});
在传递数据的地方,我尝试使用撇号而不是page_number
。它的404错误可能在frontedn中,但无论如何我附加django urls.py
字符串以防万一:
url(r'^loadmore/(?P<page_number>[0-9]+)/$', views.loadmore),
和views.py函数,这没关系:
@api_view(['GET', ])
def loadmore(request,page_number):
answers_to_questions_objects = Question.objects.filter(whom=request.user.profile).filter(answered=True).order_by('-answered_date')
paginator = Paginator(answers_to_questions_objects,10)
current_page = (paginator.page_number)
answers = serializers.serialize('json', current_page)
data = {
'answers': answers
}
return Response(data)`
答案 0 :(得分:0)
对于您的网址,您应该拨打volatile(), [], @each
之类的网址,但是您可以拨打/loadmore/2/
这样的电话。所以你的ajax应该是这样的:
/loadmore/?page_number=2