DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX基礎知識 >> PJBLOG中用到的ajaxjs.幾個簡單的函數
PJBLOG中用到的ajaxjs.幾個簡單的函數
編輯:AJAX基礎知識     
function $(id)
{
    return document.getElementById(id);    
}
function echo(obj,html)
{
    $(obj).innerHTML=html;
}
function fopen(obj)
{
    $(obj).style.display="";
}
function fclose(obj)
{
    $(obj).style.display="none";
}
function createxmlhttp()
{
    var xmlhttp=false;
    try    {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } 
    catch (e) {
          try {
               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } 
        catch (e) {
               xmlhttp = false;
         }
     }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
          xmlhttp = new XMLHttpRequest();
                if (xmlhttp.overrideMimeType) {//設置MiME類別
            xmlhttp.overrideMimeType('text/xml');
        }
    }    

    return xmlhttp;    
}

function getdata(url,obj1,obj2)
{

        var xmlhttp=createxmlhttp();
        if(!xmlhttp)
        {
            alert("你的浏覽器不支持XMLHTTP!!");
            return;
        }
        xmlhttp.onreadystatechange=requestdata;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
        function requestdata()
        {

                fopen(obj1);
                echo(obj1,"正在加載數據,請稍等......");
                if(xmlhttp.readyState==4)
                {
                    if(xmlhttp.status==200)
                    {
                        if(obj1!=obj2){fclose(obj1);};
                        echo(obj2,xmlhttp.responseText);

                    }
                }

        }
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved