【发布时间】:2016-10-14 10:05:44
【问题描述】:
我有一个视图,它首先显示数据库中的最新 ID 和与该 ID 相关的数据。
请在此处查看示例表格。 http://i63.tinypic.com/s2gyhc.jpg
我想获取显示的 ID,将其发送到我的视图,递增并显示与下一个 ID 对应的数据。
我已经将 ID 发布到视图中。现在如何在不刷新的情况下显示新数据?
Ajax 代码
$("#next").click(function(e){
$.ajax({
type:'POST',
url:'/next/',
data:{
voucher_id:$('#id_voucher_id').val(),
csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
},
success:function(){
alert('yo!')
}
});
return false;});
Views.py
def master_detail_next(request):
author_form = TmpForm()
''' Decide what we want to show'''
if request.method == 'POST':
author = TmpForm(request.POST)
voucher_id = str(int(request.POST['voucher_id']) + 1)
''' Define the three forms here'''
author = TmpPlInvoice.objects.get(voucher_id=voucher_id)
author_form = TmpForm(instance=author)
return render_to_response('main.html',
{'form': author_form},
context_instance=RequestContext(request))
如何在 Django 模型表单/Ajax 中执行此操作?
【问题讨论】:
标签: jquery ajax django django-forms django-views