Axios快速入门
image.png
Axios的get请求
servlet
@WebServlet("/AxiosServlet")
public class AxiosServlet extends HttpServlet {
protected void doGet(HttpServletRequest rst, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("hello Axios");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
html
<script src = "js/axios-0.18.0.js"></script>
<script>
axios({
method:"get",
url:"http://localhost:8080/webDemo/AxiosServlet?username=zhangsan"
}).then(function (resp){
alert(resp.data);
}
)
</script>
请求结果
2
Axios的post请求
<script src = "js/axios-0.18.0.js"></script>
<script>
axios({
method:"post",
url:"http://localhost:8080/webDemo/AxiosServlet",
data:"username=zhangsan"
}).then(function (resp){
alert(resp.data);
}
)
</script>
Axios请求别名
4
axios.get("http://localhost:8080/webDemo/AxiosServlet?username=zhangsan").then(function (resp){alert(resp.data)})
//post
axios.post("http://localhost:8080/webDemo/AxiosServlet","username=zhangsan").then(function (resp){alert(resp.data)})