• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Ajax相关的Js方法_jquery

jquery 搞代码 7年前 (2018-06-12) 163次浏览 已收录 0个评论

增加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’;

}

 

欢迎大家阅读《Ajax相关的Js方法_jquery,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Ajax相关的Js方法_jquery

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址