当前位置: 首页 > 图文教程 > 网络编程 > AJAX技术 > ajax 不错的应用

AJAX技术
什么是ajax的定义
ajaxrequest.js ajaxrequest 0.7最新版 使用AJAXRequest进行AJAX应用程序开发入门小技巧
javascript ajax类AJAXRequest2007-12-31 更新
ajax类AJAXRequest v0.8.01 2008-01-31 最新版附使用帮助
php ajax无刷新分页,支持id定位
js统计网页在线时间的脚本
用Ajax读取xml文件的简单例子
Ajax 的六个误区小结分析
Ajax核心XMLHTTP组件资料
ie7下利用ajax跨域盗取cookie的解决办法
ajax AjaxDownloader.js[modified]
Ajax获取页面被缓存的解决方法
php ajax无刷新上传图片实例代码
ajax实时任务提示功能的实现代码
php ajax网站浏览统计功能的简单实现
rails制作rss feed代码
一句话解决AJAX中文乱码问题[推荐]
有史以来最简单的AJAX回调库
使用ajax技术无刷新动态调用股票信息
ajax实例入门代码

AJAX技术 中的 ajax 不错的应用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 47 ::
收藏到网摘: n/a

<script type="text/javascript" language="javascript">

var http_request = false;

function makeRequest(url) {

http_request = false;

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);

}

function alertContents() {

if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
} else {
alert('There was a problem with the request.');
}
}

}
</script>
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('test.html')">
Make a request
</span>

点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]