How to implement asynchronously submit classes and support cross-domain in Ajax
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