一些不错的js函数ajax

//创建组件
function createobj() {
if (window.ActiveXObject) {
return(new ActiveXObject("Microsoft.XMLHTTP"));
}
else if (window.XMLHttpRequest) {
return(new XMLHttpRequest());
}
}

var cs;
//发送请求
function sxs(Fileid) {
if (window.ActiveXObject) {
cs=new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
cs=new XMLHttpRequest();
}
var my_url="inc/setsession.ASP?id="+Fileid+"&rnd="+Math.random();
cs.open("get",my_url,true);
cs.send(null);
}

//调用并返回结果
function Star() {
var oBao=createobj();
var frm= document.logo_frm;
var my_url="logo.ASP?name="+frm.username.value+"&pw="+frm.pwd.value+"&rnd="+Math.random();
oBao.open("POST",my_url,false);
oBao.send('');
var strResult = unescape(oBao.responseText);
if (strResult=="yes") {
window.location.reload();
}
else {
alert("登录失败!请重新登录...");
frm.username.value="";
frm.pwd.value="";
hide();
}
}
var h_id;
var h_i=0;
//调用并返回结果,菜单
function getinfo(index) {
var oBao=createobj();
var cont=document.getElementById("menu_detial");
cont.style.top='142px';
cont.style.left=event.x-60;
if(!bro_n){
cont.style.top='142px';
cont.style.left=event.x-60;
}
cont.style.width='150px';
cont.style.display="block";
cont.innerHTML="请等待,加载中...";
cont.style.height="10px";
cont.style.overflowY="hidden";
var my_url="getinfo.ASP?type="+index+"&rnd="+Math.random();
oBao.open('post',my_url,true);
oBao.onreadystatechange=function(){
var cont=document.getElementById("menu_detial");
if(oBao.readyState==4){
if(oBao.status==200){
cont.innerHTML=oBao.responseText;
h_i=0;
h_id=window.setInterval("h_change()",30);
}else{
cont.innerHTML='出现错误,错误代码为:'+oBao.status;
}
}
}
oBao.send('');
}

function h_change(){
var cont=document.getElementById("menu_detial");
h_i+=1;
h=parseInt(cont.style.height);
if(h>133){
window.clearInterval(h_id);
h_i=0;
}else{
cont.style.height=16+8*h_i-h_i*h_i*0.1+"px";
}
}


//调用并返回结果
function personalInfo(index) {
var oBao=createobj();
var cont=document.getElementById("person_detial");
var cont_a=document.getElementById("person_content");
cont.style.display='block';
cont.style.width="600px";
cont.style.top=event.y;
cont_a.innerHTML="请等待,加载中...";
var my_url="getinfo.ASP?type="+index+"&rnd="+Math.random();
oBao.open('post',my_url,true);
oBao.onreadystatechange=function(){
var cont_a=document.getElementById("person_content");
if(oBao.readyState==4){
if(oBao.status==200){
cont_a.innerHTML=oBao.responseText;
}else{
cont_a.innerHTML='出现错误,错误代码为:'+oBao.status;
}
}
}
oBao.send('');
}

//调用并返回结果
function getNotice(id) {
var oBao=createobj();
var my_url="notice.ASP?id="+id+"&rnd="+Math.random();
oBao.open('get',my_url,true);
oBao.onreadystatechange=function(){
var cont_a=document.getElementById("notice");
if(oBao.readyState==4){
if(oBao.status==200){
if(cont_a){
cont_a.innerHTML=oBao.responseText;
}
}else{
cont_a.innerHTML='出现错误,错误代码为:'+oBao.status;
}
}
}
oBao.send('');
}

var notice_id=window.setInterval("getNotice(0)",6000);

//调用并返回结果
function getnoticeById(id) {
var cont_a=document.getElementById("stip_detial");
cont_a.style.display="block";
cont_a.style.top=event.y;
cont_a.style.left=event.x-145;
cont_a.innerHTML="加载中...";
var oBao=createobj();
var my_url="getstip.ASP?id="+id+"&rnd="+Math.random();
oBao.open('get',my_url,true);
oBao.onreadystatechange=function(){
if(oBao.readyState==4){
if(oBao.status==200){
if(cont_a){
cont_a.innerHTML=oBao.responseText;
}
}else{
cont_a.innerHTML='出现错误,错误代码为:'+oBao.status;
}
}
}
oBao.send('');
}

JavaScript技术一些不错的js函数ajax,转载需保留来源!

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。