1.引入axios的js文件
演示一番(当然这个文件是需要自己下载的)
我会事先创建一个在webapp下创建一个js目录,方便管理。
然后在webapp下创建对应的html文件,之后就可以写axios
这里的URL写自己响应的路径
下面我分别用get和post写了,大家依葫芦画瓢就行了
//1.get
<script src="js/axios-0.18.0.js"></script>
<script>
//1.get
axios({
method:"get",
url:"http://localhost:8080/ajax-demo/axiosServlet?username=zhangsan"
}).then (function (resp){
alert(resp.data);
})
//2.post
axios({
method:"post",
url:"http://localhost:8080/ajax-demo/axiosServlet",
data:"username=zhangsan"
}).then (function (resp){
alert(resp.data);
})

2.使用axios 发送请求,并获取响应结果
下面我放了一个axios官网链接
axios官网
哈哈哈,学到新的内容,又来编辑一番
axios请求方式别名(其实就是简化了上面的写法,只是不方便阅读,上面那个提示了method,data,URL)
//1.1get
axios.get("http://localhost:8080/ajax-demo/axiosServlet?username=zhangsan").then (function (resp) {
alert(resp.data);
})
//2.1post
axios.get("http://localhost:8080/ajax-demo/axiosServlet"+"username=zhangsan").then (function (resp) {
alert(resp.data);
})