【问题标题】:Using plupload with aspx page form submission使用 plupload 和 aspx 页面表单提交
【发布时间】:2011-07-19 21:15:33
【问题描述】:

一点背景。我正在使用 plupload 在我的应用程序中上传文件。

传递的url 是我处理文件的所有处理的aspx 的url。

发生的情况是,当您第一次浏览并选择一个文件时,什么也没有发生。第二次,它立即回发两个表单提交。

你能从下面的代码中找到任何明显的遗漏吗?

// Initialize the uploader
uploader = new plupload.Uploader({
                    runtimes: 'html5,gears,flash,silverlight,browserplus',
                    browse_button: 'browse',
                    drop_element: 'uploadContainer',
                    container: 'uploadContainer',
                    max_file_size: '10mb',
                    multi_selection: false,
                    url: 'someURLHere',
                    filters: [{ title: "Pdf files", extensions: "pdf"}]
                });

FilesAdded 事件在(显然)添加文件时触发

// File Added event 
uploader.bind('FilesAdded', function (up, files) {
                    $.each(files, function (i, file) {
                        // Add element to file object
                        file.formattedSize = plupload.formatSize(file.size);

                    $('form').submit();

                    // Reposition Flash/Silverlight
                    up.refresh();
                });

提交表格

$('form').submit(function (e) {
                    uploader.start();
                    e.preventDefault();
                });

HTML

<form id="uploadForm">
   <div id="uploadContainer">
     <span id="uploadDragText" style="display: none;">Drag and Drop items here</span
     <div id="fileList"></div>
     <button id="browse" class="ButtonSubmit">Browse...</button> 
   </div>
</form>

我以这个很好的答案作为起点。 using Plupload with ASP.NET/C#

【问题讨论】:

    标签: javascript jquery plupload


    【解决方案1】:

    解决这个问题实际上非常简单。

    我需要init() 上传者之前我将任何事件绑定到它,因为init() 实际上绑定了一些默认处理程序。

    // Initialize the uploader
    uploader = new plupload.Uploader({
                        runtimes: 'html5,gears,flash,silverlight,browserplus',
                        browse_button: 'browse',
                        drop_element: 'uploadContainer',
                        container: 'uploadContainer',
                        max_file_size: '10mb',
                        multi_selection: false,
                        url: 'someURLHere',
                        filters: [{ title: "Pdf files", extensions: "pdf"}]
                    });
    
    
       uploader.init();
    
       // Then add in any of your event handlers.
    

    【讨论】:

      猜你喜欢
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 2011-01-04
      • 2011-10-11
      • 2013-12-08
      • 2011-05-25
      • 1970-01-01
      相关资源
      最近更新 更多