今天老师去参加婚礼了,请了一个新的老师来给我们简单的讲了一下ajax
和jquery只是简单的给我们讲了一下基本上就只是认识一下的感觉。
照例给大家推荐几个网站:
慕课网:https://www.imooc.com/
w3c:https://www.w3school.com.cn/
菜鸟教程:https://www.runoob.com/
如果想要自己学习一下加深一下自己的可以多去这三个网站去看看
接下来说一下老师给我们讲的东西,
真的很浅但是我们听得很懵逼,
还没有给我们讲解服务器那面的内容和接口相关的内容,我们就已经全部阵亡了;
1.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
window.onload=function(){
var xmlHttp=new XMLHttpRequest();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4 && xmlHttp.status==200){
var text=xmlHttp.responseText;
alert(text);
}
}
xmlHttp.open("GET","http://172.31.34.108:9003/hello",true);
xmlHttp.send();
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
window.onload=function(){
var xmlHttp=new XMLHttpRequest();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4 && xmlHttp.status==200){
var text=xmlHttp.responseText;
alert(text);
}
}
xmlHttp.open("POST","http://172.31.34.108:9003/world",true);
xmlHttp.send();
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript ">
function fn1(){
$.get("http://172.31.34.108:9003/jaget",
function (data) {
alert(data);
});
}
window.onload=function(){
fn1();
}
// xmlHttp.open("POST","",true);
// xmlHttp.send();
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript ">
function fn2() {
//使用Jquery发送post请求
$.post("http://172.31.34.108:9003/jajson",
{"username":"SJZZYJSXY"
,"password":"word"
},
function (data) {
alert(data);
});
}
//定义入口函数
window.onload=function () {
//调用方法
fn2();
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
//定义入口函数
function fn1() {
/**
* url 请求路径
* async: boolean 是否异步
* data: 请求参数
* dataType: 后台响应数据类型
* type: 请求方式
* success:成功以后回调方法
* error :响应失败以后的回调方法
*/
$.ajax({
url:"http://172.31.34.108:9003/login",
data:{"uname":"sy","pwd":"sy"},
dataType :"text",
type:"POST",
success:function(resutlt) {
alert(resutlt);
},
error:function () {
alert("error"+'');
}
});
}
window.onload=function () {
//调用方法
fn1();
}
</script>
</head>
<body>
</body>
</html>