欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

一些不错的js函数ajax_javascript技巧

程序员文章站 2022-04-29 11:37:23
...
//创建组件
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('');
}
相关标签: js函数