ExtJS 4.2 Data cross-domain issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.