程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> Ajax相關的Js方法

Ajax相關的Js方法

編輯:.NET實例教程
增加AJax相關的JS方法,這些方法大部分是基於prototype (一個很好的 JavaScript Framework )類庫來寫的。

1. loadAjaxElement,loadAjaxData,sendAjaxElement,sendAjaxData這四方法都是真接AJax操作的方法;

2. parseXML,importXML,getTextNodeValue這三個方法是對於AJax返回結果中的xml數據的處理;如果返回結果非標准xml文檔的話,可以通過parseXML來處理,生成XMLDocument對象;

3.getParams方法是用來返回當前頁面的url參數值的;

4.showLoading,hideLoading這兩個方法用來顯示在頁面加載過程中提示信息;



//AJax功能;

function loadAJaxElement(e,u,p,f,l){

    if(arguments.length < 3){

        return ;

    }

    var o = $(e);

    o.innerHtml = l;

    if(typeof p != 'string'){

        p = $H(p).toQueryString();

    }

    new AJax.Updater( {success: e},u,{method: 'get', parameters: p, onFailure: f});

}

function loadAJaxData(u,p,s,f){

    if(arguments.length < 3){

        return ;

    }

    if(typeof p != 'string'){

        p = $H(p).toQueryString();

    }

    new AJax.Request(
u,{method: 'get', parameters: p, onSuccess:s,onFailure: f});

}

function sendAJaxElement(e,u,p,f,l){

    if(arguments.length < 3){

        return ;

    }

    var o = $(e);

    o.innerHtml = l;

    if(typeof p != 'string'){

        p = $H(p).toQueryString();

    }

    new AJax.Updater(
{success: e},
u,
{method: 'post', parameters: p, onFailure: f});

}

function sendAJaxData(u,p,s,f){

    if(arguments.length < 3){

    return ;

    }

    if(typeof p != 'string'){

        p = $H(p).toQueryString();

    }

    new AJax.Request(
u,
{method: 'post', parameters: p, onSuccess:s,onFailure: f});

}

function parseXML(s){

    try{

        var domParser = new DOMParser();

        var o = domParser.parseFromString(s,
'application/XML');

        return o.documentElement;

    }catch(e){

        try{

            var o = getIEXMLAX();

            o.loadXML(s);

            return o.documentElement;

        }catch(e){

            return null;

        }

    }

}

function importXML(u,s,f){

    new AJax.Request(
u,
{method: 'get', parameters: null, onSuccess:function(v){s(v.responseXML.documentElement);},onFailure: f});

}

function getIEXMLAX(){

    var i,activeXarr;

    activeXarr = new Array(

                                "MSXML4.DOMDocument",

                                "MSXML3.DOMDocument",

                                "MSXML2.DOMDocument",

                                "MSXML.DOMDocument",

                                "Microsoft.XMLDom"

    );

    for(i=0; i
        try
{

            var o = new ActiveXObject(activeXarr[i]);

            return o;

        }
catch(objException){}

    }

    return false;

}

function getTextNodeValue(d,n,e){

    if(typeof e == 'undefined'){

        e = false;

    }

    var a = d.getElementsByTagName(n);

    if(a==null){

        return null;

    }

    if(a.length==1){

        return (e)?unescape(a[0].firstChild.nodeValue):a[0].firstChild.nodeValue;

    }else{

        var ra = new Array();

        for(var i=0;i
            ra[i] = (e)?unescape(a[i].firstChild.nodeValue):a[i].firstChild.nodeValue;

        }

        return ra;

    }

}

function getParams(){

    var o = new Object()

    var a=document.location.search.substr(1).split('&');

    for (i=0;i
        try{

            var aa=a[i].split('=');

            var n=aa[0];

            var v=aa[1];

            o[n]=trim(v);

        }catch(e){

        }

    }

    return o;

}

function showLoading(c,b,a){

    switch(arguments.length){

        case 2:

            a = 0.9;

        case 1:

            b = "#000000";

        case 0:

            c = "#FFFFFF";

        break;

    }

    var d = document;

    if($("loading_div") == null){

    var s = '

';

    d.write(s);

    }

    var o = $("loading_div");

    if(o.style.MozOpacity){

        o.style.MozOpacity = a;

    }else if(o.style.opacity){

        o.style.opacity = a;

    }else{

        a = a * 100;

        o.style.filter='Alpha(Opacity='+a+')';

    }

}

function hideLoading(){

    $("loading_div").style.display = 'none';

}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved