pagination.js ajax,javascript - Creating ajax pagination - Stack Overflow

I am trying to do an ajax pagination with the following code:

// AJAX pagination

$(".pages .prev").live('click', function(event) {

event.preventDefault()

var current_page = parseInt(getParameterByName('page'))-1;

$.get('/ajax/financial_page/', {'page': current_page}, function(response) {

$(".content table").replaceWith(response)

});

})

And in my view function:

def financial_page(request):

"""

Returns a single financials page, without extra HTML (used in AJAX calls).

"""

page = int(request.GET.get('page', 1))

if request.user.is_superuser:

fs = FinancialStatements.objects.order_by('-date', 'statement_id')

else:

up = request.user.get_profile()

providers = up.provider.all()

fs = FinancialStatements.objects.filter(provider__in=providers).order_by('-date', 'statement_id')

fs_objects, current_page_object, page_range = paginator(request, objects=fs, page=page, number_per_page=30)

data = { 'fs':fs_objects,

'page_range': page_range,

'current_page': current_page_object,

}

page = render_to_string('financial_section.html', data, RequestContext(request))

return HttpResponse(simplejson.dumps([page]))

However, there are two problems I'm running into. The first is that the response is not really HTML, and has a bunch of n\t\t\n\t\t\n\t\n\t\n\t\n\t\t\n\t\, etc. Also, I'm having trouble keeping track of the current page/changing the url as needed. How would I build a functional ajax pagination here?

Update: I figured out the first one, by doing response = $.parseJSON(response);. How would I keep track of which page I am on though?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值