如何使用jQuery或JavaScript发送/上传文件? [英] how to send/upload file using jquery or javascript?
本文介绍了如何使用jQuery或JavaScript发送/上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用jquery ajax将文件信息发送/上传到php? info是要上传的文件.
How to send/upload file information to php using jquery ajax? info is the file to be uploaded.
$.ajax({
type: "POST",
url: url,
data: data, /* data from input file to upload it */
async: false,
beforeSend: function() {
},
complete: function() {
},
cache: false,
success: callback,
error: function(error) {
alert("Some problems have occured. Please try again later: " + error);
}
});
<form id="product-form" action="javascript: product();" enctype="multipart/form-data">
<input type="file" name="img" />
<a href="#" class="link2" onclick="document.getElementById('product-form').submit()">Submit</a>
</form>
推荐答案
您不能仅使用jQuery来做到这一点.您需要使用jQuery插件,例如 HTML 5 .请注意,目前并非所有浏览器都支持HTML 5,因此jQuery Uploadify可能是更好的选择.
You cannot do this with jQuery alone. You need to either use a jQuery plugin such as Uploadify or use HTML 5. Please note that not all browsers support HTML 5 at this time, so jQuery Uploadify may be the better choice.
这篇关于如何使用jQuery或JavaScript发送/上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文