一个jQuery插件,用于“静默”上传单个文件

a jquery plugin to upload a single file 'silently'

本文关键字:单个 文件 静默 jQuery 插件 用于 一个      更新时间:2023-09-26

在我的网络应用程序中,当用户选择该文件并保持在同一html页面上时,我需要上传该文件。我正在寻找一种可能使用 jquery 的非闪存解决方案,并且可以在 Firefox 上运行。

通过谷歌搜索,我遇到了许多插件,其中大多数使用精心设计的 html 页面来显示input widgets / upload status indicators等。我需要一些我可以像这样使用的东西,使用 ajax。

我的页面.html

<input type="file" id="myfileselect" > </input>

我的.js

$(document).ready(function(){
   $('#myfileselect').change(function(e){
       //upload the file somehow
   }
});

这可能吗?有人可以说明我该怎么做吗?

我在所有项目中都使用此插件。用户选择文件后,您只需调用

$('#yourForm).ajaxSubmit()

它将异步上传您的文件。

http://jquery.malsup.com/form/

在您的情况下,您可以这样做:

.HTML

<form id="myForm">
<input type="file" id="myfileselect" > </input>
</form>

杰奎里

$(document).ready(function(){
    //set the options here
    var options = {
        url : 'yourScript.php',
        method : 'post'
    };
   $('#myfileselect').change(function(e){
       $('#myForm').ajaxSubmit(options);
   }
});