使用ajax请求上传文件[副本]
Possible Duplicate:
How can I upload files asynchronously with JQuery?可能重复:如何使用JQuery异步上传文件?
I'm submiting my forms like this.
像这样提交表单。
var url = event.currentTarget.action;
var values = $(this).serialize();
$.post(url, values, function (data) {
//some code
});
Now I have a form with a file upload input. With this code the file isn't uploaded.
现在我有一个带有文件上载输入的表单。使用此代码,文件不会被上传。
How can I include the file into this ajax request ? I don't want to use any plugin if possible(except jQuery).
如何将文件包含到这个ajax请求中?如果可能的话,我不想使用任何插件(除了jQuery)。
1 个解决方案
#1
2
You can only upload files with AJAX but only in some modern browsers. I know it works in Firefox and Chrome (That's all I've tested so far).
您只能使用AJAX上传文件,但只能在一些现代浏览器中。我知道它可以在Firefox和Chrome上运行(这就是我到目前为止所测试的)。
Theres some good info here about it: https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest
这里有一些关于它的好信息:https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest
As an alternative there's a great plugin for that sort of thing:
作为一种替代方法,有一个很棒的插件可以用来做这类事情:
http://jquery.malsup.com/form/
http://jquery.malsup.com/form/
This part may be of relevance to you:
这部分可能与你有关:
http://jquery.malsup.com/form/#file-upload
http://jquery.malsup.com/form/文件上传
It uses iframes to post to to upload in a background style of way.
它使用iframe以一种背景风格上传。
更多相关文章
- 如何在Ajax.ActionLink中获取表单中的输入数据?
- 动态添加表单元素,将它们存储到MySQL并在将来更改/删除它们
- 使用JQuery从外部文件中通过id选择器获取html内容
- Ajax php登录表单不指向另一个页面
- 分享27款非常棒的 jQuery 表单插件
- 如何使用jQuery的叠加对话框作为反馈表单
- GET ajax请求发送到同一个php文件
- 无法使用jquery发送简单的ajax请求来获取json文件
- 在上传前预览xls、xlsx、doc等文件的缩略图