ajax,axios基本使用

ajax

<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
 $.get({
 	url:"",
 	data :{参数名:参数值,key:value},
 	dataType:"json",//可有可无
 	success: function (data) {
 		alert("成功");
 		//成功回调参数
 		//data.message 例子
 	},
 	error: function () {
 		alert("失败")
 	}
 })

 $.post({
 	url:"",
 	data :{参数名:参数值,key:value},
 	dataType:"json",//可有可无
 	success: function (data) {
 		alert("成功");
 		//成功回调参数
 		//data.message 例子
 	},
 	error: function () {
 		alert("失败")
 	}
 })
 </script>

axios

//淡入script
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
axios.get("url",{params:{key:value,参数名:参数值}}
	).then(response=>{layer.msg("成功")}).catch(layer.msg("失败"))


var params = new URLSearchParams();
params.append(key,value)
params.append(参数名,参数值)
axios.post("url",
	params).then(response=>{layer.msg("成功")}).catch(layer.msg("失败"))


</script>


你可能感兴趣的:(ajax,jquery,post,get)