jQuery的阿贾克斯文件上传 [英] jQuery Ajax File Upload

查看:212
本文介绍了jQuery的阿贾克斯文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用下面的jQuery code。使用Ajax请求POST方法来进行文件上传?

Can I use the following jQuery code to perform file upload using post method of an Ajax request ?

$.ajax({
    type: "POST",
    timeout: 50000,
    url: url,
    data: dataString,
    success: function (data) {
        alert('success');
        return false;
    }
});

如果有可能,我需要填写的数据的一部分?这是不是正确的方法是什么?我只发布文件到服务器端。

If it is possible, do I need to fill "data" part? Is it the correct way? I only post the file to the server side.

我一直在谷歌搜索周围,但我发现了一个插件,而在我的计划,我不希望使用它。至少在那一刻。

I have been Googling around, but what I found was a plugin while in my plan I do not want to use it. At least for the moment.

推荐答案

文件上传<打击>不是可以通过AJAX。 您可以通过使用IFrame的上传文件,无需刷新页面。 你可以在这里查看更详细的

file upload is not possible through ajax. You can upload file, without refreshing page by using IFrame. you can check further detail here

更新:

通过XHR2,文件上传,通过AJAX支持。例如。通过 FORMDATA 的对象,但遗憾的是,并不是所有的/旧的浏览器的支持。

With XHR2, File upload through AJAX is supported. E.g. through FormData object, but unfortunately it is not supported by all/old browsers.

FORMDATA支持启动浏览器版本。 IE 10+, 火狐4.0 +, Chrome浏览器7+, Safari浏览器5+, 歌剧12 +

FormData support starts from following desktop browsers versions. IE 10+, Firefox 4.0+, Chrome 7+, Safari 5+, Opera 12+

有关更多详细信息,请参见 MDN链接

For more detail, see MDN link

这篇关于jQuery的阿贾克斯文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆