Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement asynchronously submit classes and support cross-domain in Ajax

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how Ajax implements asynchronous submission of classes and supports cross-domain. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The code is as follows:

/ *

Asynchronous request class

Author: I am not unintentional

Creation time: 2009.2

-

Modify the record:

2009.4.27Mel-add URL detection, if it is "http://xxxx.xxx.xx.xx/.." This format can be obtained using the "/ getUrl.aspx" provided by the system.

To solve cross-domain problems.

There are two main parameters of getUrl.aspx: 1. The url value is the target URL (you can have parameters in URL)-- must be; 2. The method value is the method used by the agent (optional)

If method is empty, the POST method is used by default; if the FORM parameter is empty (that is, request.content-length=0), it is automatically set to the GET method

(note: getUrl.aspx redesigned on April 27, 2009, adding a Cookie agent on the basis of the original completed agent.)

, /

Function IsOuterURL (str_url) {

Var strRegex = "((https | http): / / ([\\ w -] +\\.) + [\\ w -] +. ([^ aMaiz]) (/ [\\ wlash% yield =] *)? | ((https | http): / / [a-zA-Z0-9\\ -\.] [\\ w -] +. ([^ aripz]) (/ [\\ w.Universe% yield =] *)?"

Var re=new RegExp (strRegex)

If (re.test (str_url)) {

Return (true)

} else {

Return (false)

}

}

Var LeesAjaxRequest=

{

List: []

M_LeesAjaxHttpRequest:null

IsWorking:false

GetUrl:function (method,url,params,successFun,FailureFun,headers)

{

If (url.length0)

{

Var o=_this.list [0]

_ this.list.splice (0Pol 1)

_ this.getUrl (o.methodmethod o.urlrecovero.paramsauthoro.recording Funauthoro.failureFunauthoro.headers)

}

}

}

Var vPara= ""

If (typeof params== "string")

{

VPara=escape (params)

}

Else if (params)

{

Try

{

For (var e in params)

{

If (vPara.length

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report