Study on the JSONP cross-domain request of Sencha Touch

Source: Internet
Author: User

This article is the study of their own in the process of learning Sencha touch record, mainly JSONP cross-domain request this aspect, for Wei he is cross-domain concept and unfamiliar, you can ask the mother.

First Picture:

I want to complete the function is the table drop-down refresh, and send the request to my own writing service terminal, because the service program and this Sencha program is no longer a domain, there is always a request error (the approximate information is a cross-domain problem). These two days is really tortured by this problem for a long time, because did not touch the Sencha touch Jsonp, began also confused, also read a lot of information. Finally understood the JSONP's request pattern in Sencha.

This is roughly what it means (see picture):

Look at the request URL, when requested in JSONP mode, Sencha will automatically generate a CALLBACK=EXT.DATA.JSONP.CALLBACK3 parameter, this is a callback, other you do not care, as long as the server to return a similar

Ext.data.JsonP.callback2 ([{"Name": "Li Yang 1", "Age": "$", "Potourl": "http://img5.duitang.com/uploads/item/201408/05/ 20140805170730_b5cza.jpeg "}]), the returned type should be text/javascript, that is, the method body of a JavaScript is returned, so that when the request is complete, The server returns the result and is automatically injected into the callback in the form of a script to execute. That's all I can understand.

The following can be affixed to the server code: I am using the ASP. NET Web API Services

[HttpGet]  Public Httpresponsemessage getallcontacts (string _dc,string page,string Start, String limit,string callback)// Data method supported in JSONP format        {          person[] Persons = new person[]           {   new person () {Name = "Li Yang 1", age = "$", potourl= "http:/" /img5.duitang.com/uploads/item/201408/05/20140805170730_b5cza.jpeg "}                         };          String content = String. Format ("{0} ({1})", Callback, Jsonconvert.serializeobject (Persons));          var response=  request.createresponse (Httpstatuscode.ok, content);          Response. Content = new Stringcontent (content, Encoding.UTF8, "Text/javascript");          return response;       }

Study on the JSONP cross-domain request of Sencha Touch

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.