第一种用最简介方便的$.post请求后端数据
$.post("你的url地址",{
data//填写后台给的参数
},function(res){
console.log(res)
})
第二种通过$.ajax的写法请求后端数据
$.ajax({
type: 'post',
url: "你的url地址",
cache: false,
data: {//后台给的参数},
dataType: 'json',//通过json格式返回
success: function(res){
console.log(res)
},
error: function(err){
console.log(err)
return;
}
});
举例:以第一种为例请求后台数据(我一般用第一种简介的方式不行再用第二种)
$.post("https://app.xiaozhangnongming.vip/api.html",{
"method":"website.pcphoto"
},function(res){
console.log(res)
})
想了解如何将后台请求的数据遍历到页面可以点击这里
更多推荐
如何用ajax请求后台数据的两种全网最实用且详细的写法
发布评论