【发布时间】:2015-12-11 07:22:26
【问题描述】:
好的,正如标题所描述的,我正在尝试创建一个网页(test.html),在提交表单后它应该将我重定向到一个新页面(比如 status.html)。在这个页面加载之后它应该显示提交任务的一些持续更新。当我尝试将其重定向到新页面时,我能够在单个页面上完成此操作,但我不走运。
test.html
<form action="status/" method="POST" id="start-form">
.....
<input type="submit" value="Start" class="tbutton">
views.py
def status_page(request):
print("Inside redirect")
return HttpResponseRedirect(request,'my_app/status.html')
url.py
url(r'^test/status/$', 'status_page'),
jav.js
$('#start-form').on('submit',function(event){
event.preventDefault();
status();
});
function status() {
$.ajax({
url : "status_page/", // the endpoint
type : "POST", // http method
data:{' ': '',}, // data sent with the post req
headers: {Accept: "application/json"},
success : function(json) {
//on success display the rendered page,so what coding is needed here?
},
error : function(xhr,errmsg,err) {
//error handling code }
});
}
在执行时不会加载新页面,但如果我绕过 javascript,则会执行表单操作并通过视图呈现新页面。但是使用 JavaScript,成功后会发生什么?视图中的返回语句如何在成功中捕获以及页面如何显示? 我需要使用 javascript 和 AJAX,因为一旦加载了新页面,我需要在同一页面上显示持续更新。那么基本上如何使用 javascript 和 Django 使用上述代码实现对新页面的重定向?任何帮助将不胜感激!
【问题讨论】:
标签: javascript html django