一点背景。我正在使用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"}]
                });


当添加文件(显然)时,将触发FileFyreed事件

// 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#

最佳答案

解决方法实际上非常简单。

在绑定任何事件之前,我需要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.

关于javascript - 在plx页面表单提交中使用plupload,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6754255/

10-12 12:20
查看更多