Ajax-related JS methods

Source: Internet
Author: User
Tags array return string split
Ajax|js
Add AJAX-related JS methods, most of which are based on prototype (a good JavaScript Framework) class library.

1. Loadajaxelement,loadajaxdata,sendajaxelement,sendajaxdata these four methods are true to connect the Ajax operation method;

2. Parsexml,importxml,gettextnodevalue these three methods are the processing of XML data in the Ajax return results, which can be handled by parsexml if the results are not standard XML documents. Generate XmlDocument objects;

The 3.getParams method is used to return the URL parameter value of the current page;

4.showloading,hideloading These two methods are used to show the information during the page loading process;



AJAX features;

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 ';

}




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.