<script type="text/javascript">
//定义入口函数
window.οnlοad=function () {
//创建ajax引擎对象
var xmlHttp= new XMLHttpRequest();
//绑定监听事件
xmlHttp.onreadystatechange=function () {
//判断网络状态码,获取服务器返回结果
if(xmlHttp.readyState==4&&xmlHttp.status ==200){
//获取网络请求结果
var text=xmlHttp.responseText;
//弹出对话框提示响应内容
alert(text);
}
}
//绑定请求url
/**
*method: string, url: string, async?
* method:请求方式:POST,GET
* url : 后台请求路径: 比如www.baidu.com
* async: boolean :true或是false true代表异步请求,false:同步请求
*/
xmlHttp.open("GET","http://localhost:9003/hello",true);
//发送qingqiu
xmlHttp.send();
}
</script>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
//定义入口函数
/**'
* $.get(url, [data], [callback], [type])
* url 请求路径
* data 请求参数
* callback 回调函数
* type : 指定后台服务器给你响应类型
*/
function fn1() {
$.get("http://localhost:9003/hello",
function (data) {
alert(data);
});
}
window.οnlοad=function () {
//调用方法
fn1();
}
</script>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
//定义入口函数
/**'
* $.get(url, [data], [callback], [type])
* url 请求路径
* data 请求参数
* callback 回调函数
* type : 指定后台服务器给你响应类型
*/
function fn1() {
$.get("http://localhost:9003/hello",
function (data) {
alert(data);
});
}
window.οnlοad=function () {
//调用方法
fn1();
}
</script>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
/**
* URL,data,callback
* url:请求路径
* data就是 请求参数
* callback:服务器响应后的回调函数
*/
//定义网络请求方法
function fn2() {
//使用Jquery发送post请求
$.post("http://localhost:9003/japost",
{"username":"SJZZYJSXY"
,"password":"word"
},
function (data) {
alert(data);
});
}
//定义入口函数
window.οnlοad=function () {
//调用方法
fn2();
}
</script>