Jquery
1-1 get
$.get(url,res=>{
console.log(res)
})
$.get(url).then(res=>{
console.log(res)
})
1-2 $.ajax
$.ajax({
url,
type:"get",
data, // get传值问号后面的值,可以放在data属性里面
dataType,
success:res=>{
console.log(res);
}
})
var url ="http://192.168.4.18:3000/search"
$.ajax({
url,
type:"get",
data:{
keywords:"你"
},
success:res=>{
console.log(res);
}
})
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
2-1 get
axios.get(url).then(res=>{
console.log(res);
})
// var url = "http://192.168.4.18:3000/search?keywords=你"
axios.get("http://192.168.4.18:3000/search",{
params:{
keywords:"你"
}
}).then(res=>{
console.log(res);
})
2-2 axios
axios({
url,
baseURL,
method,
params:{} //问号后面的值
}).then(res=>{
console.log(res)
})
axios({
url:"/search",
baseURL:"http://192.168.4.18:3000",
method:"get",
params:{
keywords:"你"
}
}).then(res=>{
console.log(res);
})
2-3 axios二次封装
var baseURL="http://192.168.4.18:3000/"
function http({
url,
method:"get",
params:{}
}){
return axios({
url,
baseURL,
method,
params
})
}
http({
url:"/album?id=96964667",
}).then(res=>{
console.log(res)
})
http({
url:"/album",
params:{
id:"96964667"
}
}).then(res=>{
console.log(res)
})