在Django上重新加载Ajax中的整个页面?

我正在使用ajax去执行该函数并检查数据库中是否已存在该值。 如果数据已经存在,我会显示正常工作的jQuery对话框,但如果该值尚不存在,我不想显示弹出窗口并刷新整个页面。 这是我的AJAXfunction:

function copyFile(val) { var choices = document.getElementsByName("choice_shard_with_me").value; var file_owner = document.getElementById('username').value; $.ajax({ type: "GET", url: "/copy_file/", data: {choices:choices, file_owner:file_owner}, success: function(data){ $('#dialog-confirm').html(data) } }); } 

我的Django观点:

  if request.GET: choices = request.GET.getlist('choice_shard_with_me') file_owner = request.GET.getlist('username') #Test if the file already exist in the user share directory x = [File.objects.filter(user_id=request.user.id, file_name=i, flag='A').values_list('file_name') for i in choices] y = [y[0] for y in x[0]] if len(y) > 1: return render_to_response('copyexist.html', {'file':y}, context_instance=RequestContext(request)) //doesn't refresh the whole page show the popup. else: //refresh whole page and do something 

我的问题是:当显示弹出窗口时,它会在div中使用Ajax显示。 如果它进入else语句文件已复制完成,成功的消息在一个小div本身给出(我想在这里做整页刷新)。

你可以回答json编码,你会返回两个参数:

  { success: true/false, data : YOUR_DATA_HERE } 

因此,成功回调可以查看成功部分,并决定是显示弹出数据还是重新加载页面

对不起,我不知道python,所以不能建议精确的表达式来做出正确的json编码。