一些不錯的js函數ajax

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.