2011-07-21 50 views

回答

33

假设您使用表格:

// select the file input (using a id would be faster) 
$('input[type=file]').change(function() { 
    // select the form and submit 
    $('form').submit(); 
}); 

编辑:为了保持这个答案了最新:

有通过AJAX上传文件,而这里介绍黑客的好办法: http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/

+0

发送数据到数据库必须使用ajax调用吗?请解释更多... –

+0

@Mehd:这不是ajax。当您更改文件时,表单将自动开始发送 – genesis

+0

@Mehd:查看完整上传解决方案的成因答案。 – binarious

5

使用jQuery的插件uploadify

这是伟大的插件,它有许多选项,并自动上传,太

$(document).ready(function() { 
    $('#file_upload').uploadify({ 
    'uploader' : '/uploadify/uploadify.swf', 
    'script' : '/uploadify/uploadify.php', 
    'cancelImg' : '/uploadify/cancel.png', 
    'folder' : '/uploads', 
    'auto'  : true 
    }); 
}); 
+3

我不使用插件 –

+0

如果您想要使用html上传器,则非商业项目花费5美元,商业项目花费100美元。 – Adam

3

刚才设置的自动为true ..'auto':true

+2

你可以添加一个链接,你看到这个工作,因为我找不到像这样的东西。 –

相关问题