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以一种背景风格上传。

更多相关文章

  1. 如何在Ajax.ActionLink中获取表单中的输入数据?
  2. 动态添加表单元素,将它们存储到MySQL并在将来更改/删除它们
  3. 使用JQuery从外部文件中通过id选择器获取html内容
  4. Ajax php登录表单不指向另一个页面
  5. 分享27款非常棒的 jQuery 表单插件
  6. 如何使用jQuery的叠加对话框作为反馈表单
  7. GET ajax请求发送到同一个php文件
  8. 无法使用jquery发送简单的ajax请求来获取json文件
  9. 在上传前预览xls、xlsx、doc等文件的缩略图

随机推荐

  1. 【Android 应用开发】Android资源文件 -
  2. Ubuntu 编译Android若干错误及解决方法(
  3. Android 开关控件Switch使用
  4. Android跨进程通信IPC之16——Binder之na
  5. Android OpenGL ES基础教程
  6. Android属性系统之build.prop的生成
  7. Eclipse 安装 Google Android 插件
  8. Android必备:Android应用程序组成
  9. Android项目架构2 - Clean Architecture
  10. 基于 Android NDK 的学习之旅-----环境搭