2013-08-18 28 views
0

我有一个浏览按钮,用户可以通过它浏览高达100 MB的文件。但问题是,当用户提交表单时,它会上传attch文件。它并没有在任何地方显示多少文件上传。我想用进度条显示它。在现有的上传按钮中附加进度条

U可以访问我的网站http://historikindia.com/contact_us.php

请帮我这么做。它现在将附件发送到我的电子邮件。但我需要向用户显示进度条,否则他们可能会认为它没有正确响应(对于大文件上传)。

+0

发表您的形式请 – DevZer0

+0

我已经attched我的表单页面的链接。 http://historikindia.com/contact_us.php。 – user2693518

+0

当然,但我们看不到代码。为了回答你的问题,这是重要的。 –

回答

1

以下是更新状态栏的ajax上传器的代码。你需要在你的html页面有一个html5进度条才能使用。

function progressHandlingFunction(e){ 
    if(e.lengthComputable){ 
     $('progress').attr({value:e.loaded,max:e.total}); 
    } 
} 

$('#btnupload').click(function(){ 
       var formData = new FormData(document.getElementById('fileupload')); 
       $.ajax({ 
        url: 'upload.php', //server script to process data 
        type: 'POST', 
        xhr: function() { // custom xhr 
         myXhr = $.ajaxSettings.xhr(); 
         if(myXhr.upload){ // check if upload property exists        
          myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload 
         } 
         return myXhr; 
        }, 
        //Ajax events 
        beforeSend: function (e) { return true; }, 
        success: function (json) { return true; }, 
        error: function (json) { return false; }, 
        // Form data 
        data: formData, 
        dataType: "json", 
        //Options to tell JQuery not to process data or worry about content-type 
        cache: false, 
        processData: false 
       }); 
      }); 

HTML5进度条看起来像这样

<progress value="1" max="100"></progress> 
+0

我加了你说的代码。我是一名html编码人员,对开发代码没有太多意义。请帮我做。我已经把你的代码,但不工作只是显示一个栏。 – user2693518

+0

你可以用你的代码 – DevZer0

+0

准备一个jsfiddle,这对我来说很难。因为我不知道这个过程。如果你需要,我可以发送文件。 – user2693518