ajax请求头设置 | header 传token
$('.w-entry-btn').on('tap',function(){ var urlAddress = '/api/address'; var valToken = JSON.parse(localStorage.getItem('token')); $.ajax({ url:urlAddress, async:true, headers:{'Accept': 'application/json','Authorization':'Bearer '+ valToken}, data:$('#info').serialize(), type:'POST', success:function(data){ if(data == 'success'){ layer.open({ content: '新建成功' ,skin: 'msg' ,time: 1 //2秒后自动关闭 }); localStorage.removeItem('defalutshopId'); localStorage.removeItem('shopId'); setTimeout(function(){ window.history.back(-1); },1000) } } }) })
$.ajax({ url:ajaxUrl, dataType:'json', async:true, headers:{'Accept': 'aplication/json','Authorization':'Bearer '+ valToken}, data:$('#report').serialize(), type:'POST', success:function(data){ setTimeout(function(){ window.location.href = '/wechat/profile'; },800); } })