The same logic code needs to be used in multiple sites, each site creates a new ashx is really a rip-off, so want to only request a ashx, so easy to maintain and modify, then, Ajax cross-domain problem comes.
Less nonsense, directly on the code, what I'm doing now is GET request. The same is the POST request.
First, the ashx is rectified, and the code that supports cross-domain requests is added.
Context. Response.ContentType ="Text/plain"; stringActive = context. request.querystring["Active"]; stringrs ="0"; if(Active = ="3") { stringOID = TGM. BaseOpera.String.replacesql (context. request.querystring["OID"]); if(!string. IsNullOrEmpty (OID)) {Tansar. Bll.order TBO=NewTansar. Bll.order (); stringFlag =TBO. GetSID (OID); if(Flag! =" +") RS="OK"; } } #regionSupport cross-domain requestscontext. Response.ClearHeaders (); stringOrigin = context. request.headers["Origin"]; Context. Response.appendheader ("Access-control-allow-origin",string. IsNullOrEmpty (Origin)?"*": Origin); stringRequestheaders = context. request.headers["access-control-request-headers"]; Context. Response.appendheader ("access-control-allow-headers",string. IsNullOrEmpty (requestheaders)?"*": Requestheaders); Context. Response.appendheader ("Access-control-allow-methods","POST, GET, OPTIONS"); #endregion context. Response.Write (RS);
Then the JS method in Ajax:
functionGetflag (d) {$.ajax ({type:"Get", Async:false, URL:"Http://www.8kmm.com",
Data:D,
DataType:"Text",
Success:function(data) {
if (data = = "OK") {
Location.href = "/user/orderdetail.aspx?oid=<%=onumber%>";}
},
Error: function (XMLHttpRequest, Textstatus, Errorthrown) {
alert ("Request data exception:" + Errorthrown);
}
});
}
To do front-end development, browser developer tools can be a big help, such as the WebKit kernel, ff.
jquery Ajax GET POST cross-domain request implementation