教程
https://www.w3school.com.cn/jquery/ajax_ajax.asp
ajax上传文件的代码
<script type="text/javascript">
function postData(){
var formData = new FormData();
formData.append("photo",$("#photo")[0].files[0]);
formData.append("service",'App.Passion.UploadFile');
formData.append("token",token);
$.ajax({
url:'http://www.baidu.com/', /*接口域名地址*/
type:'post',
data: formData,
contentType: false,
processData: false,
success:function(res){
console.log(res.data);
if(res.data["code"]=="succ"){
alert('成功');
}else if(res.data["code"]=="err"){
alert('失败');
}else{
console.log(res);
}
}
})
}
网友评论