let url = "https://www.fastmock.site/mock/39aa306dc9dec321fb0237a30b3040d2/api"
// 使用jquery ajax 获取数据
$.ajax({
type:"get", //请求方式
url:url+"/newList", //请求地址
success:function(res){ //请求成功返回的回调
console.log(res); //请求成功得到的数据
},
error:function(){ //请求失败的回调
console.log("请求失败")
}
})
$.ajax({
type:"POST",
url:url+"/login",
data:{ //请求需要用到的参数
username:'admin',
password:'123456'
},
success:function(res){
console.log(res);
},
error:function(){
console.log("请求失败")
}
})
$.ajax({
type:"put",
url:url+"/change",
data:{
username:'ghahgah',
password:'456'
},
success:function(res){
console.log(res);
},
error:function(){
console.log("请求失败")
}
})
// 使用axios 获取数据
axios({
method: 'get',
url:url+"/newList",
}).then(res=>{ //请求成功得到的数据
console.log(res)
}).catch(function(err){ //请求失败的回调
console.log("请求失败")
})
axios({
method: 'post',
url:url+"/login",
data:{ //请求需要用到的参数
username:'admin',
password:'123456'
}
}).then(res=>{
console.log(res)
}).catch(function(err){
console.log("请求失败")
})
axios({
method:'put',
url:url+"/change",
data:{
username:'admin',
password:'789'
}
}).then(res=>{
console.log(res)
}).catch(function(err){
console.log("请求失败")
})