PHP代码,例如:
<input type="file" name="photo" id="photo" value="" style="width:100px;height:30px;" />
<input type="button" onclick="postData2();" value="下一步" name="" style="width:100px;height:30px;" />
script代码,例如:
<script type="text/javascript">
localStorage.setItem("token",'e7e6238fde352eeb0aba417df305c497');//储存名称为“key”的值
var token = localStorage.getItem("token");//获取名称为“key”的值
function postData2(){
var formData = new FormData();
//接口接收参数 键值形式 添加到formData中
formData.append("photo",$("#photo")[0].files[0]);
formData.append("service",'App.Bel-Ami.Info');
formData.append("token",token);
$.ajax({
url:'http://baidu.com/',//url地址
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);
}
}
})
}
</script>