On the cross-domain, in the development of the project will inevitably encounter; before the author used EXTJS3.0 development project, in the development process encountered about cross-domain issues, but found on the internet most of the information is ExtJs4.0 or above version of
In ExtJS, for example: Ext.Ajax.request, this is the way we use data requests, as in the following code:
Ext.Ajax.request ({URL:'serviceapiorm.ashx? Api=save', params: {Name:'Zhang San'}, Method:'POST', Success:function (req) {alert ("Success"); alert (Req.responsetext); }, Failure:function (req) {alert (req.responsetext); }, });
But rewritten as a cross-domain:
Ext.Ajax.request ({URL:'Http://localhost:3722/ServiceAPIORM.ashx?API=Save',//cross-domain linksparams: {Name:'Zhang San'}, Method:'POST', Success:function (req) {alert ("Success"); alert (Req.responsetext); }, Failure:function (req) {alert (req.responsetext); }, });
Such a request must not succeed.
Resolving Cross-domain:
1. In ExtJs4.2, there are JsonP can be resolved, but only with GET request way to submit, so there is a certain flaw and insufficient, this logic is in the Ext.data.JsonP.reques ({}) property, Callbackkey: " Jsonpcallback ", as a parameter to the background,
Then accept in the background in the delivery to the foreground, format: Response:Ext.data.JsonP.callback1 ({success:true,data: ' ssss '})
Front-End Code:
Ext.data.JsonP.request ({URL:'Http://localhost:3722/ServiceAPIORM.ashx?API=Save', timeout:300000, params: {Name:'123456'}, Callbackkey:"Jsonpcallback", Success:function (req) {alert ("Success"); alert (Req.responsetext); }, Failure:function (result) {alert (req.responsetext); } });
Back-End Code:
Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; stringMethod = Context. request.querystring["API"]; Switch(method) { Case "Save": Save (context); Break; } } /// <summary> ///Save/// </summary> /// <param name= "context" ></param> Private voidSave (HttpContext context) {stringJsonpcallback =""; Jsonpcallback= Context. request["Jsonpcallback"]; Context. Response.ContentType="Text/javascript"; Context. Response.Write (Jsonpcallback+"({success:true,data: ' ssss '})"); }
JS cross-domain, the following is about JS cross-domain links
http://blog.csdn.net/iispring/article/details/7428069
Asp. NET Communication Group (1 groups): ExtJS AC Group (3 groups):
ExtJS 4.2 Data cross-domain issues