[英]Server side redirect not working after jQuery upload script
I have the following code for a simple web page where I want to let a user upload, track the upload progress and then redirect them after the upload is complete (this I need to do on thr server side) It works just fine without the bottom script to show the upload progress. 我在一个简单的网页上有以下代码,我想让用户上传,跟踪上传进度,然后在上传完成后重定向它们(我需要在服务器端执行此操作)。脚本来显示上传进度。 Is there something in the ajax call that is preventing the redirect?
Ajax调用中是否存在阻止重定向的内容? My backend is in Python on Google App Engine and I would be glad to show the code but I don't think it is relevant.
我的后端使用的是Google App Engine上的Python,我很乐意展示代码,但我认为这无关紧要。
<style>
.progress { position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
.bar { background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px; }
.percent { position:absolute; display:inline-block; top:3px; left:48%; }
</style>
<div class="row">
<div class="span12">
<div class="center-it"><h1>Upload a Video:</h1><br>
</div>
<form action="{{upload_url}}" method="POST" enctype="multipart/form-data">
<input type="file" name="file" class="btn"><br>
<input type="submit" name="submit" value="Submit" class="btn">
</form>
</div>
</div>
<div class="progress progress-striped active">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
#without everything below this line it works just fine
<script>
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
}
});
})();
</script>
Without Ajax it works because the form is submitted to a different page on server where you can redirect to another URL then. 如果没有Ajax,它会起作用,因为表单已提交到服务器上的其他页面,然后您可以在其中重定向到另一个URL。 With Ajax though it's still in the same page and only receives a response from server.
使用Ajax,尽管它仍在同一页面中,并且仅收到来自服务器的响应。
You can send the URL as part of the response and then use window.location
or window.navigate
in JavaScript to redirect to the new URL. 您可以发送URL作为响应的一部分,然后在JavaScript中使用
window.location
或window.navigate
重定向到新URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.