如何将用户发送到上传页面而不是显示响应

时间:2014-04-24 18:18:43

标签: javascript php jquery html ajax

我发现此代码可以将进度条添加到上传表单中。此代码显示表单下的上传页面的响应,我希望将用户重定向到上传页面并查看响应                       0%     

<div id="status"></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>
     <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);
      },
       complete: function(xhr) {
           bar.width("100%");
           percent.html("100%");
           status.html(xhr.responseText);
        }
   }); 

   })();       
   </script>

提前致谢

1 个答案:

答案 0 :(得分:0)

只需在完成进度后更改window.location

所以你的完整事件将是这样的。

 complete: function(xhr) {
               bar.width("100%");
               percent.html("100%");
               status.html(xhr.responseText);
               window.location.replace("http://stackoverflow.com");// or url of your choice
            }

要更好地了解javascript重定向,请参阅此SO thread.