post传对象
axios.post:返回promise对象
url参数:拼接
body参数:传对象
1.无参数get
function getcoupon(){
$.get("http://193.112.55.79:9090/api/getcoupon",function(res){
console.log(res);
模板,看文档
var html =template("saleTpl",{arr:res.result});
// 渲染页面
$(".sale ul").html(html);
})
}
2.带参数id,get
function getcouponproduct(){
console.log(location.href);
//couponproduct.html?couponId=0
var couponId = location.href.split('?')[1].split('=')[1];//截取网址的id号
$.ajax({
url:"http://193.112.55.79:9090/api/getcouponproduct",
data:{
couponid:couponId//id
},
type:"get",
dataType:"json",
success:function(res){
console.log(res);
var html = template("sale_list",{arr:res.result});.//模板,看文档
$(".list ul").html(html);//渲染页面
}
})
}
3.获取url的参数(?id=2)
getUrl: function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
},