2014-04-24 19 views
0

我发现此代码可将进度条添加到上传表单。此代码是从上传页面的形式下的响应,我希望用户被重定向到上传页面,看到的响应有 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> 

感谢

+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.

+0

这里用户将被重定向到一个静态页面。而我需要他被重定向到上传页面,在那里他的上传和网址显示 – user3530661

+0

什么是你的上传页面的网址 – Shiva

+0

这里是我的表单头action =“upload.php”method =“POST” – user3530661

相关问题