Heim > Web-Frontend > js-Tutorial > 一些不错的js函数ajax_javascript技巧

一些不错的js函数ajax_javascript技巧

WBOY
Freigeben: 2016-05-16 19:01:45
Original
955 Leute haben es durchsucht

//创建组件
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('');
}

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage