Results 1 to 7 of 7

Thread: Ajax request using Jsonp

  1. #1
    Sencha User
    Join Date
    Dec 2009
    Location
    Tokyo
    Posts
    46
    Vote Rating
    0
      0  

    Question Ajax request using Jsonp

    Hello,

    When I look at the examples and the document, it seems that the jsonp proxy only works with the store. Unfortunately, I really need to use an Ext.Ajax.request, and I thought that, logically, using the jsonp proxy would do the trick, but it doesn't.

    Any ideas? Thanks a lot.

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    You're not comparing like for like. Proxies are a higher level abstraction than Ext.Ajax.request(), providing a uniform way for stores to load their data. An Ajax proxy would use an Ajax request, other proxy types do not.

    The equivalent of Ext.Ajax for JSONP is Ext.data.JsonP:

    http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.JsonP

    You'll notice the API is quite similar to that of Ext.Ajax but the technique it uses is very different.

    You haven't explained exactly why you need to use Ext.Ajax.request(). It should be noted that it is impossible (due to browser security restrictions) to load data from a different server using an Ajax request - this is why JSONP exists in the first place.

  3. #3
    Sencha Premium User mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,153
    Answers
    33
    Vote Rating
    203
      0  

    Default

    It should be noted that it is impossible (due to browser security restrictions) to load data from a different server using an Ajax request - this is why JSONP exists in the first place.
    Not entirely true, checkout HTTP access control. https://developer.mozilla.org/en/http_access_control
    and http://www.w3.org/TR/cors/

    Supported by modern browsers, demo of using Ext 3 + CORS here: http://bryntum.com/playpen/BBC/bbc.html

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    @mankz. Thanks for the links, not sure how much they'll help the OP but I found them interesting. In the right circumstances this could certainly be a useful technique.

  5. #5
    Sencha User
    Join Date
    Dec 2009
    Location
    Tokyo
    Posts
    46
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by skirtle View Post
    You haven't explained exactly why you need to use Ext.Ajax.request(). It should be noted that it is impossible (due to browser security restrictions) to load data from a different server using an Ajax request - this is why JSONP exists in the first place.
    I need indeed to load data from a different server. I know well how JSONP operates and I naturally thought that it would work with the Ext.Ajax.request (the aim is to perform an asynchronous request still) + the JSONP proxy. The 'callbackKey' would enable the framework to call an internal callback that would then itself call "success". Wouldn't be neat if it was working this way?

    Thanks for guiding me to Ext.data.JsonP, it's what I'm looking for indeed. I just wonder why it's not possible to do it with the Ext.Ajax.request + JSONP proxy. Maybe because the implementation of Ext.Ajax.request don't let enough room for the proxies to do much?

  6. #6
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,234
    Answers
    756
    Vote Rating
    1015
      0  

    Default

    A proxy, as the name suggests, is the intermediary that fetches the data from a particular source. In this case, Ext.Ajax ~is~ the proxy, it's specifically designed to retrieve data over HTTP.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  7. #7
    Sencha User
    Join Date
    Dec 2009
    Location
    Tokyo
    Posts
    46
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by evant View Post
    A proxy, as the name suggests, is the intermediary that fetches the data from a particular source. In this case, Ext.Ajax ~is~ the proxy, it's specifically designed to retrieve data over HTTP.
    Thanks for the clarification, I didn't really understand Ext.Ajax as a proxy (as its parent is Ext.data.Connection), but more as an asynchronous connection sending data and retrieving data (json, xml, whatever) through a proxy (using default Ext.data.proxy.Ajax or Ext.data.proxy.JsonP, rest).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •