最简单的JQuery + AJAX
2016-07-30 14:51
351 查看
test.html Jquery版本的Ajax
test2.html 非Jquery版本的Ajax
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<title>Test Jquery+ AJAX2</title>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("resText").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.php?a=123&b=567",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="container">
<input type='button' id='send' onclick="loadXMLDoc()" value='test' />
<span id='resText' ></span>
</div>
</body>
</html>
test.php
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8"> <title>Bootstrap 实例 - 标签式的导航菜单</title> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script> $(function(){ $('#send').click(function(){ $.ajax({ type: "GET", url: "test.php", data: 'a=123&b=456', success: function(data){ $('#resText').empty(); //清空resText里面的所有内容 $('#resText').html(data); } }); }); }); </script> </head> <body> <div class="container"> <input type='button' id='send' value='test' /> <span id='resText'></span> </div> </body> </html>
test2.html 非Jquery版本的Ajax
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<title>Test Jquery+ AJAX2</title>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("resText").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.php?a=123&b=567",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="container">
<input type='button' id='send' onclick="loadXMLDoc()" value='test' />
<span id='resText' ></span>
</div>
</body>
</html>
test.php
<?php echo $_GET['a']."=".$_GET['b']; ?>
相关文章推荐
- jQuery对象和DOM对象
- jQuery控制 checkbox单选
- jquery 全国三级联动
- 自己编写JQuery扩展分页插件
- 商城项目总结(二)
- jQuery绑定事件的四种方式
- jquery 遍历表格,需要表格中每个td的内容
- jQuery-黑白反斗棋
- jQuery-制作黑白反斗棋页面
- CSS 选择器、jQuery选择器大全
- 用jquery怎么删除<table>的一行
- jQuery全屏滚动插件FullPage.js中文帮助API
- JQuery重命名库名
- jQuery过滤选择器:not()方法使用介绍
- jQuery ajax - getScript() 方法和getJSON方法
- jQuery动画效果(show与hide/toggle/slideUp/slideToggle/fadeIn/fadeTo)
- 避免jQuery名字冲突 noConflict()方法
- jquery 性能优化
- jQuery Mobile 自定义导航条图标
- 自定义jQuery Mobile工具栏按钮