我的html页面中有input
个元素。当用户按下提交按钮时,即使在jquery中它也被绑定到click
并且数据正在被验证,然后使用AJAX发送到服务器。问题是,我有一个file
字段。那么如何使用AJAX通过代码启动文件上传?
示例代码:
$(function(){
$('#btnSubmit').on('click', function(){
// validate fields, make some processing on the data, etc.
// then send to server using AJAX...
$.ajax({
//....
});
// after submitting the above data or along with it, I want the picture uploaded(without user having to press upload button or anything)
});
});
怎么做?