In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
AJAX的使用是怎样,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
首先是一个创建AJAX的函数:
代码如下:
var http_request=null;
function create_ajax(){
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) { //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
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) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
}
然后是调用这个函数来处理AJAX
代码如下:
var obj1;
function get_ajax(url,obj) {//初始化、指定处理函数、发送请求的函数
obj1=obj;
create_ajax();
http_request.onreadystatechange =processobj; // 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("POST", url, true);
http_request.send(null);
}
function processobj(){
document.getElementById(obj1)[xss_clean]="Loading...";
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
document.getElementById(obj1)[xss_clean]=http_request.responseText;
} else { //页面不正常
document.getElementById(obj1)[xss_clean]="loading error.";
}
}
}
以上就是AJAX的主体,再在你需要用AJAX的页面把这段Javascript包含进去,就可以方便的调用了:
代码如下:
Welcome.
d2
d2
'ajax/get1.jsp'和'ajax/get2.jsp',是两个后台获取数据的页面,这样,一点击d1,get1.jsp就会被动态的加载进来,非常方便,当然这只是一个最基本的功能的模型,还可以在上面加上很多功能,大家自由发挥吧。
看完上述内容,你们掌握AJAX的使用是怎样的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.