如何使用 jquery ajax 向 php 发送/上传文件信息?info 是要上传的文件。
$.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>