我有一個文件輸入類型的HTML表單。我需要將表單異步提交給服務器。服務器偵聽傳入文件上傳(多部分文件上傳)請求。是否有可能實現這個使用jQuery。異步JQUERY文件上傳
0
A
回答
1
是否有可能實現這個使用jQuery。
不,不直接用jQuery。
你可以使用HTML5文件API:https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
或者,如果你需要支持舊版瀏覽器,你可以使用一些插件如Uploadify
,Fine Uploader
或jQuery form plugin
。
0
我想看看這個jQuery插件:
2
您可以輕鬆地使用jQuery的$.ajax()
方法來發送文件,如果FormData和File API支持(包括HTML5功能)。
您也可以發送文件without FormData,但無論採用哪種方式,都必須存在File API來處理文件,以便可以使用XMLHttpRequest(Ajax)發送文件。
$.ajax({
url: 'file/destination.html',
type: 'POST',
data: new FormData($('#formWithFiles')[0]), // The form with the file inputs.
processData: false // Using FormData, don't process data.
}).done(function(){
console.log("Success: Files sent!");
}).fail(function(){
console.log("An error occurred, the files couldn't be sent!");
});
有關快速,純粹的JavaScript示例,請參閱「Sending files using a FormData object」。
如果你想添加一個後備舊版本瀏覽器,或者如果你只想要一個跨瀏覽器實現使用Bifröst。它增加了一個額外的jQuery Ajax transport允許發送文件與飛機舊$.ajax()
。
只需添加jquery.bifrost.js和發出請求:
$.ajax({
url: 'file/destination.html',
type: 'POST',
// Set the transport to use (iframe means to use Bifröst)
// and the expected data type (json in this case).
dataType: 'iframe json',
fileInputs: $('input[type="file"]'), // The file inputs containing the files to send.
data: { msg: 'Some extra data you might need.'}
}).done(function(){
console.log("Success: Files sent!");
}).fail(function(){
console.log("An error occurred, the files couldn't be sent!");
});
祝你好運!
相關問題
- 1. 問題jQuery異步文件上傳
- 2. 角異步上傳文件
- 3. IE8異步文件上傳
- 4. 在上傳期間取消異步jquery文件上傳
- 5. CakePHP jQuery異步上傳
- 6. AjaxFileupload多個異步文件上傳
- 7. GWT和異步文件上傳 - 幫助
- 8. 使用mootools異步文件上傳?
- 9. 如何異步上傳ActionScript文件?
- 10. Windows Azure:多文件異步上傳
- 11. 如何異步上傳大文件
- 12. 排隊異步HTTP文件上傳
- 13. 異步文件上傳點擊
- 14. 異步後臺多文件上傳?
- 15. ajax文件上傳與異步
- 16. 上傳文件異步地MVC.NET
- 17. 異步FTP上傳文件列表
- 18. 多個異步文件上傳asp.net
- 19. 使用jquery和python進行異步文件上傳
- 20. 異步在asp.net中使用jquery上傳文件
- 21. 使用jquery和ASP.NET進行異步文件上傳
- 22. IE jquery異步文件上傳請求正在進行中
- 23. 使用jQuery的ASP.NET MVC異步文件上傳
- 24. HTML5異步文件上傳,上傳的流總是無效
- 25. 異步FTP上傳
- 26. SlickUpload異步上傳
- 27. (jQuery文件上傳)maxFileSize行爲怪異
- 28. 使用jsp和javascript進行異步文件上傳(AJAX文件上傳)
- 29. Jquery文件上傳,分兩步啓動上傳
- 30. 異步jQuery上傳似乎仍然上傳到Heroku
可能重複的[我怎樣才能上傳文件與jQuery異步?](http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery) – gdoron 2013-08-31 19:33:35