Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

javascript - jQuery Ajax文件上传(jQuery Ajax File Upload)

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

(我可以使用以下jQuery代码使用ajax请求的POST方法执行文件上传吗?)

$.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?

(如果有可能,我是否需要填写data部分?)

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.

(至少目前是这样。)

  ask by Willy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

file upload is not possible through ajax.

(文件上传是 不可能 通过Ajax。)

You can upload file, without refreshing page by using IFrame.

(您可以使用IFrame上传文件,而无需刷新页面。)

you can check further detail here

(您可以在此处查看更多详细信息)

UPDATE:

(更新:)

With XHR2, File upload through AJAX is supported.

(使用XHR2,支持通过AJAX上传文件。)

Eg through FormData object, but unfortunately it is not supported by all/old browsers.

(例如,通过FormData对象,但不幸的是,所有/旧的浏览器均不支持。)

FormData support starts from following desktop browsers versions.

(FormData支持从以下桌面浏览器版本开始。)

IE 10+, Firefox 4.0+, Chrome 7+, Safari 5+, Opera 12+

(IE 10以上版本,Firefox 4.0以上版本,Chrome 7以上版本,Safari 5以上版本,Opera 12以上版本)

For more detail, see MDN link

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...