簡體   English   中英

使用 plupload 和 aspx 頁面表單提交

[英]Using plupload with aspx page form submission

一點背景。 我正在使用 plupload 在我的應用程序中上傳文件。

傳遞給我的 aspx 的url是 url,我在其中處理文件的所有處理。

發生的情況是,第一次瀏覽 select 文件時,什么也沒有發生。 第二次,它立即回發兩個表單提交。

你能從下面的代碼中找到任何明顯的遺漏嗎?

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

我以這個很棒的答案為起點。 通過 ASP.NET/C# 使用 Plupload

解決這個問題實際上非常簡單。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM