The newly written Ajax functions include IE6, IE7, IE8, FF, Safari, Google, and opera.

Source: Internet
Author: User
The newly written Ajax class should be very simple. Application Example: Format: req (URL, {Asyn: synchronous or asynchronous, true | false. The default value is true, that is, asynchronous DAT: included data, the default value is null. RDT indicates the data type to be returned. The default value is text. xml or jsontimeout is optional: [millisecond, function for timeout execution]. array. Default Value: [9000, ""] cache: whether to cache is actually adding a random form in the URL: whether to submit the form and the form ID. If the ID is available, the form is also submitted. Loading: ['display loading status id', 'display content'], data or ID. The text displayed only when the ID is being sent... Done: the function that is executed at completion. It can be an ID or a function. If it is an ID, the result is assigned to this ID. Only one parameter extra is allowed. The additional parameter is in the prototype done (, b, C, D) the first parameter of done is forcibly added, that is, txt, XML, or JSON, followed by B, c, D is an additional parameter. You do not need to use an array when [B, c, d] is an array .}) 1. submitted in get mode. No req ("test. PHP "); 2. submitted in post mode. No req ("test. PHP ", {type: 'post'}) 3.req( 'test. PHP ', {Asyn: false, type: 'post', done: Alert, loading: 'status', form: 'myform', timeout: [1000, 'alert ("request time-out") '], cache: false, dat: "A = XX & B = YY & C = ZZ, RDT: 'json '"}) post to test. PHP submits a myform and disables Ajax caching. Parameters A, B, and C are included. If the submission time exceeds 1 second, a timeout occurs, during the submission process, the Status Control shows that the request is being sent .. ', The result is returned by alert. The result is that the JSON type is displayed as an object problem: the second parameter of timeout, which cannot be a function directly. Otherwise, it will be executed as soon as it is executed. If you have any suggestions, contact me via qq For function req (u, O) {var P = {Asyn: True,/* asynchronism */type: "Post", dat: "",/* Data */RDT: "TXT",/* reponsedatatype */Timeout: [90000, ""], cache: True, fail: function (E, U, t, D, S) {u = "http: //" + window. location. host + getroot (U); alert ("Error Type: [" + E + "] \ Nuri: ["+ u +"] ["+ T +"] \ n \ ndata: {"+ D +"} "); window. clipboardData. setdata ("text", ("Post" = T. tolowercase ())? U + (U. Match (/\? /)? '&':'? ') + D: U) }}; for (var key in O) {P [Key] = O [Key]} p. type = P. type? P. type. tolowercase (): "Get"; var r = getxhr (), L = P. loading, L, S, I, C, x = false, Z; VaR _ g = function (a) {var A =? A: "autogenelement _" + math. Ceil (math. Random () * 1000); var S = (typeof (A) = "object ")? A: Document. getelementbyid (a); var G = (! S )? True: false; If (g) {var J = Document. createelement (B? B: "span"); J. style. Display = "inline-block"; document. Body. appendchild (j)} return (! S )? J: s}; VaR _ S = function (a, B) {If (! A) return; try {var o = _ g (B); If ("| input | textarea | option | ". indexof (O. nodename. tolowercase ()>-1) O. value = A; else {o. style. display = ''; O. innerhtml = A} return O} catch (e) {}}; VaR _ B = function (s) {return (typeof (S) = "string "? (S = Document. getelementbyid (s ))? S: false)}; VaR _ n = function (s) {return (typeof (s) = 'undefined' | S = "null" | S = "" | S = NULL? "": Escape (s ). replace (/\ +/g, '% 2B '). replace (/\ "/g, '% 22 '). replace (/\ '/g,' % 27 '). replace (// G, '% 2f')}; VaR _ t = function (s) {return object. prototype. tostring. call (o) = '[object array]'}; If (! L) L = false; else if ('string' = typeof (L) {L = true; C = NULL; I = L; S = false} else if (_ T (L) {L = true; I = L [0], c = L [1]; S = L [2]} else l = false; function _ A (U, S) {If (! U. nodename) return; var v = "|" + U. nodename. tolowercase () + "|"; if ("| input | textarea | option | ". indexof (v)>-1) u. value = s; else u. innerhtml = s} function _ q (s) {try {var x = P. extra; var d = P. RDT. tolowercase (); var M = D & D = "XML "? R. responsexml: R. responsetext; If (D = "JSON") eval ("m =" + M); If (typeof (S) = "function ") {var y = [m]; If (isnull (x) return S (m); else if (_ T (x) Y. push. apply (Y, x); else y. push (x); S. apply (S, Y)} else {var T = _ B (s); If (t) _ A (t, M ); else if ("string" = typeof (s) eval (s); else S (m) }}catch (e) {}} VaR _ f = function (z) {var u = "", y = "", t = z. elements, V, A; For (VAR x = 0; x <t. length; ++ X) {v = T [X]; If (v. name! = "") {A = undefined; Switch (v. type) {Case "select-one": If (v. selectedindex>-1) A = v. options [v. selectedindex]. value; else a = ""; break; Case "select-multiple": var S = v. options; For (var w = 0; W <S. length; + + W) {If (s [w]. selected) U + = Y + v. name + "=" + _ n (s [w]. value); y = "&"} break; Case "checkbox": Case "radio": If (v. checked) A = v. value; break; default: A = v. value; break} if (! = Undefined) {A = _ n (a); U + = Y + v. name + "=" + A; y = "&" }}} return u}; If (_ B (p. form) {var F = P. form; F = f? _ B (F): NULL; If (! F | f. nodename! = "Form") return; k = f. getattribute ("method"); p. type = (! K )? "Get": K. tolowercase (); var c = _ F (f); If (C. length = 0) return; p. DAT + = P. dat. length> 0? '&' + C: c} var P _ = (P. type = "Post ")? True: false; var u = u + = (P. cache )? "" :( (U. Match (/\? /)? '&':'? ') + "Ascrnd =" + new date (). gettime (); If (! Post) U + = (U. Match (/\? /)? '&':'? ') + P. dat; var z = setTimeout (function () {x = true; R. abort ()}, P. timeout [0]); VaR _ r = function () {If (x) {If (l) show ("sending request timeout", I) eval (P. timeout [1])} else if (R. readystate = 4) {cleartimeout (z); try {If (R. status = 200) {If (l) {Show ("request completed", I); If (S &&! Isnan (s) setTimeout (function () {(I = _ B (I ))? I. style. display = 'none': ''}, S)} _ q (P. done)} else {var T = ""; Switch (R. status) {Case 400: t = "HTTP Error 400-request format error"; break; Case 403: t = "HTTP Error 403-Access prohibited: Access Denied"; break; case 404: t = "HTTP Error 404-file or directory not found"; break; Case 500: t = "HTTP Error 500-internal server error"; break; default: T = "request error! \ N "+ R. status + "/" + R. statustext} If (P. fail) {If (l) show (t, I); p. fail (t, u, P. type, P. dat, R. status) }}} catch (e) {}}; try {R. open (P. type, U, P. asyn) if (l) _ s (C? C: "sending... ", I); If (P _) R. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded"); R. send (P. type = "get ")? Null: P. dat); If (P. asyn) R. onreadystatechange = _ r; else _ r ()} catch (e) {If (L) (_ S (E. message, I ))}};

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.