<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn">点击</button>
</body>
<script>
var btn=document.getElementById("btn");
btn.=function(){
//1.创建ajax对象(此处兼容性的创建)
var xhr=null;
try{
xhr=new XMLHttpRequest();
}catch(e){
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
//2.调用open方法----注:xhr.open("方法","路径?数据","是否异步")
xhr.open("get","links/2.get.php?username="+encodeURI('陆小曼')+"&age=18&timp="+new Date().getTime(),true);
//3.发送数据
xhr.send();
//4.请求状态改变事件
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
document.write(xhr.responseText)
}else{
alert("错误"+xhr.status)
}
}
}
}
</script>
</html>点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦