axios

Introduction

Axios是一个基于promise网络请求库,作用于node.js和浏览器中。它是isomorphic的(即同套代码可以运行在浏览器和node.js中) 在服务端它使用原生node.js http模块,而在客户端(浏览端)则使用XMLHttpRequests

特性

Get Started

  1. 引入axios的js文件
<script src="js/axios-0.18.0.js"></script>
  1. 使用axios发送请求,并获取响应结果
axios({
	method:"get",
	url:"http://localhost:8080/ajax-demo1/aJAXDemo1?username=zhangsan"
)).then(function (resp){
	alert(resp.data);
})
axios({
	method:"post",
	url:"http://localhost:8080/ajax-demo1/aJAXDemo1",
	data:"username=zhangsan"
}).then(function (resp){
	alert(resp.data);

为了方便起见,Axios已经为所有支持的请求方法提供了别名

axios.get(url[,config])
axios.delete(url[,config])
axios.head(url[,config])
axios.options(url[,config])
axios.post(url[,data[,config]])
axios.put(url[,data[,config]])
axios.patch(url[,data[,config]])
axios.get("url")
	.then(function(resp){
		alert(resp.data);
});
axios.post("url","参数")
	.then(function(resp){
		alert(resp.data);
});