AJAX 基础
来源:互联网 发布:淘宝微淘在哪里 编辑:程序博客网 时间:2024/06/05 03:45
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
var xhr = null;
//创建xhr
function createXHR() {
if (window.XMLHttpRequest) {//DOM2浏览器
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {//IE
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
//发送请求
function ajax() {
createXHR();
xhr.open("POST", "http://localhost:8080/ajax", true);//method方式最好是大写,firefox敏感,如GET、POST
xhr.onreadystatechange = execute;
xhr.send(null);
}
//回调函数
function execute() {
if (xhr.status === 200 && xhr.readyState === 4) {
console.info(xhr.responseText);
document.getElementsByTagName("p")[0].innerHTML = xhr.responseText;
}
}
// ajax();
</script>
</head>
<body>
<p>hello</p>
<input type="button" value="变" onclick="ajax()" />
</body>
</html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
var xhr = null;
//创建xhr
function createXHR() {
if (window.XMLHttpRequest) {//DOM2浏览器
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {//IE
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
//发送请求
function ajax() {
createXHR();
xhr.open("POST", "http://localhost:8080/ajax", true);//method方式最好是大写,firefox敏感,如GET、POST
xhr.onreadystatechange = execute;
xhr.send(null);
}
//回调函数
function execute() {
if (xhr.status === 200 && xhr.readyState === 4) {
console.info(xhr.responseText);
document.getElementsByTagName("p")[0].innerHTML = xhr.responseText;
}
}
// ajax();
</script>
</head>
<body>
<p>hello</p>
<input type="button" value="变" onclick="ajax()" />
</body>
</html>
0 0
- Ajax 基础
- Ajax基础
- Ajax基础
- AJAX基础
- AJAX基础
- ajax基础
- ajax基础
- Ajax 基础
- ajax基础
- AJAX基础
- AJAX 基础
- Ajax基础
- Ajax基础
- AJAX 基础
- ajax基础
- AJAX基础
- Ajax基础
- Ajax基础
- 成功的背后!(给所有IT人)
- 简单的商品操作
- C++中值传递,地址传递,引用传递的区别
- redis缓存服务器在java中的使用
- 面向对象 第一课
- AJAX 基础
- yffs2 移植 linux2.6.37
- Android Studio出现Gradle '×××' project refresh failed 解决办法
- 面向对象 第二课
- maven 环境变量配置
- 解决No “rule to make target `../Database/images/login.png', needed by `debug/qrc_image.cpp'. Stop.”
- poj1503
- 面向对象 第三课
- 2015-09-10