Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write an encapsulated Ajax class

Shulou Source: shulou.com Published: 2022-06-03 07:38:58 11月15日 Update

This article focuses on "how to write an encapsulated Ajax class", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write an encapsulated Ajax class.

Usage:

New Ajax () Request (url,cmd,async,method,postString,title)

Parameters:

Url: request page URL (required)

Cmd: return value handler (required)

Async: whether asynchronous, (ture | false), default true

Method: request method, (post | get), default get

PostString: request content when the request method is post

Title: request content title

The code is as follows:

/ / Ajax package 2007-3-13

Function createXMLHttpRequest () {

Try {

If (window.XMLHTTPRequest) {

Return new XMLHttpRequest ()

}

Else if (window.ActiveXObject) {

Return new ActiveXObject ("Microsoft.XMLHTTP")

}

}

Catch (e) {alert ("XMLHttpRequest object cannot be created! please check IE security settings!") ;}

}

Function messageDiv (t)

{

Var v = document.createElement ("")

V [XSS _ clean] = "" +

"" +

"" +

"

"+ t +", the connection is not initialized. "

Var l = document.getElementsByName ("message") .length

V.style.cssText = "position:absolute;bottom:" + (lumb24) + "px;left:0px;display:none"

Document.body.appendChild (v)

This.clear = function () {

Document.body.removeChild (v)

Var msg = document.getElementsByName ("message")

For (var iTuno Bandi)

Tags: Data being encapsulating content way learning practical deeper security code interest function parameter practicality reality object simple operation method more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info Huawei Linux macOS