AJAX和AXIOS前端代码块

这是AJAX

 xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://localhost:8080/AJAXServlet", true);
xmlhttp.send();

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        alert(xmlhttp.responseText);
    }
};

这是AXIOS

//发送get请求
axios({
    method:"get",
    url:"http://localhost:8080/ajax-demo1/aJAXDemo1?username=zhangsan"
}).then(function (resp){
    alert(resp.data);
})
//发送post请求
axios({
    method:"post",
    url:"http://localhost:8080/ajax-demo1/aJAXDemo1",
    data:"username=zhangsan"
}).then(function (resp){
    alert(resp.data);
});

 

posted @ 2022-07-20 10:38  linxiaofeng  阅读(29)  评论(0)    收藏  举报