1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    cjones56 is on a distinguished road

      0  

    Default Answered: jsonp and callback1

    Answered: jsonp and callback1


    After many hours of struggling with the jsonp proxy I finally realized that the returned data had to be wrapped in a function named callback1. In particular Ext.data.JsonP.callback1().

    My question is, why then does the code below in the example "building your first application" work?

    If you type the url into you browser you will find that the resulting json object is not encapsulated in a function.

    This has been extremely misleading to me, so please explain.

    Also, I found no mention of Ext.data.JsonP.callback1() in the sencha documentation that I downloaded! Why?



    Ext.application({
    name:'Sencha', launch:function(){Ext.create("Ext.tab.Panel",{ fullscreen:true, tabBarPosition:'bottom', items:[{ xtype:'nestedlist', title:'Blog', iconCls:'star', displayField:'title', store:{ type:'tree', fields:['title','link','author','contentSnippet','content',{name:'leaf', defaultValue:true}], root:{ leaf:false}, proxy:{ type:'jsonp', url:'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog', reader:{ type:'json', rootProperty:'responseData.feed.entries'}}}}]});}});

  2. Did I use the word 'default' wrong?The dictionary told me meaning of 'default ' is:
    Computer Science A particular setting or value for a variable that is assigned automatically by an operating system and remains in effect unless canceled or overridden by the operator.
    callbackKey has a default value ,which is 'callback'!
    Code:
    function foo(value){
        var default='bar';
        return value?value:default;
    }
    foo('hello');
    foo();//you think this will return null or '' or undefinded?
    
    function fun(config){
        var defaultValue='callback';
        config=config?config:{};
        if(!config.callbackKey){
            config.callbackKey=defaultValue;
        }
        alert(config.callbackKey);
    }
    fun({name:'a',callbackKey:'jsoncallback'});
    fun({name:'b'});
    Code:
    proxy: {
        type: 'jsonp',
        url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
        reader: {
             type: 'json',
             rootProperty: 'responseData.feed.entries'
        }
        //,callbackKey:'callback'    this is default value if you do not assign!
    }
    Attachment 39731

  3. #2
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    Do you know what is jsonp?Jsonp requires the server side implementing .
    If you have implemented on server side,in your client side code,you can config the callbackKey.

    server
    Code:
    //request url: http://server/?jsoncallback=Ext.xxxx.xxxxx
    final String callbackKey='jsoncallback';
    String callbackName=request.getParameter(callbackKey);
    if(callbackName){
        response.write(callbackName+"("+ jsonData+ ")");
       //response : Ext.xxxx.xxxxx({})
    }else{
        response.write(jsonData);
        //response: {}
    }
    client
    Code:
    proxy:{
        type:'jsonp',
        url:'',
        callbackKey:'jsoncallback'
    }
    and you can test the url('callback' is default value of callbackKey)
    https://ajax.googleapis.com/ajax/ser...t.end.with.dot
    I write English by translator.

  4. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    cjones56 is on a distinguished road

      0  

    Default Maybe my question was not clear enough.

    Maybe my question was not clear enough.


    To answer your question, I am learning both json and jsonp.

    If I understand correctly jsonp is a json object wrapped in a callback function that gets injected in the page so that it is executed when the page is loaded on the client. (ie: the callback function is executed and the json object is passed to it)

    If you enter the url, found in the "Building your First App" , (see below) you only get a json object passed back from the server, please see my example.

    My question is therefore, why the example work when the url used to get the data returns only a json object?

    You will find below a snippet of what is returned in the sample project as well as what I had to return to make my test app work.

    url: https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog

    and the data returned looks like this:

    {"responseData": {"feed":{"feedUrl":"http://feeds.feedburner.com/SenchaBlog","title":"Sencha Blog","link":"http://www.sencha.com/blog/","author":"jennifer.chow@extjs.com","description":"Technical articles, company news, and customer spotlights from Sencha.","type":"rss20","entries":[{"title":"Developing Mobile Applications with Force.com and Sencha Touch - Part 1","link":"http://www.sencha.com/blog/developing-mobile-applications-with-force-com-and-sencha-touch-part-1/#date:17:00","author":"Don Robins","publishedDate":"Thu, 13 Sep 2012 10:00:00 -0700","contentSnippet":"This series of articles will introduce you to the Sencha Touch mobile framework for building HTML5 applications with ...
    Notice the data is not wrapped in a function.

    In order to get my data to work I had to return the following somehting similar to the following...


    Ext.data.JsonP.callback1({"responseData": {"feed":{"feedUrl":"http://feeds.feedburner.com/SenchaBlog","title":"Sencha Blog","link":"http://www.sencha.com/blog/","author":"jennifer.chow@extjs.com","description":"Technical articles, company news, and customer spotlights from Sencha.","type":"rss20","entries":[{"title":"Developing Mobile Applications with Force.com and Sencha Touch - Part 1","link":"http://www.sencha.com/blog/developing-mobile-applications-with-force-com-and-sencha-touch-part-1/#date:17:00","author":"Don Robins","publishedDate":"Thu, 13 Sep 2012 10:00:00 -0700","contentSnippet":"This series of articles will introduce you to the Sencha Touch mobile framework for building HTML5 applications with ...)
    My returned data is wrapped in a function

    My question is why does the example work when it only returns a json object whereas I had to return a json object wrapped in a callback function.

    What am I missing here?

  5. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    cjones56 is on a distinguished road

      0  

    Default also note:

    also note:


    in the example "Building your First App"

    there is NO callbackKey specified, either in the code or at the end of the url.

    and when using the sample provided by haduki ---

    and you can test the url('callback' is default value of callbackKey)
    https://ajax.googleapis.com/ajax/ser...t.end.with.dot


    you see the callback function being added and wrapping the resultant json object

    i cannot find where this is happening anywhere in the code for the
    "Building your First App" example.

    what am I missing?





  6. #5
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    You create a jsonp proxy, your url is 'http://localhost/',actually the reqeust is 'http://localhost/?callback=SomethingCreatedByST2'.
    (url+'?' or '&' +callbackKey+'='+callbackName)
    As i said ,'callback' is the default value of callbackKey,you can see the document
    http://docs.sencha.com/touch/2-0/#!/...ty-callbackKey
    you did not specify 'callbackKey' ,it does not mean callbackKey is null or '',it has a default value 'callback'.



    Notice the data is not wrapped in a function.
    because you did not pass the callback parameter,it is not jsonp style.
    see google document
    https://developers.google.com/feed/v...using_callback

    the jsonp actually is
    Code:
    //define callback function name first
    function getUserName(response){
        showUserName(response.userName);
    }
    function getUserAge(response){
        showUserAge(response.userAge);
    }
    //then make the request
    <script src='http://localhost/userid/userName?callback=getUserName'>
    // here is your server response,the 'getUserName' function will be called
    getUserName({userName:'name'})
    </script>
    <script src='http://localhost/userid/userAge?callback=getUserAge'>
    // here is your server response,the 'getUserAge' function will be called
    getUserAge({userAge:'21'})
    </script>

    The server never care what callbackName is,it only care if there is a callbackKey in the request parameterMap.
    I write English by translator.

  7. #6
    Sencha User
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    cjones56 is on a distinguished road

      0  

    Default you are not answering my question....

    you are not answering my question....


    My point is, that the data being returned in the Building your First App is not jsonp.
    Look at the example in the sencha touch documentation under: Building your First App

    In the code a jsonp proxy is used.

    However, there is NO callback function specified anywhere.

    (I realize that the default function name is "callback" but you still have to tell the server otherwise it returns on json data)

    The data that is returned is NOT jsonp. (paste the url into your browser and see what you get back)

    The question: Why does this work, in the Building your First App, if the data returned is NOT jsonp?


    Here is the code from the sencha documents example....

    Ext.application({
    name: 'Sencha',


    launch: function() {
    Ext.create("Ext.tab.Panel", {
    fullscreen: true,
    tabBarPosition: 'bottom',


    items: [
    {
    xtype: 'nestedlist',
    title: 'Blog',
    iconCls: 'star',
    displayField: 'title',


    store: {
    type: 'tree',


    fields: [
    'title', 'link', 'author', 'contentSnippet', 'content',
    {name: 'leaf', defaultValue: true}
    ],


    root: {
    leaf: false
    },


    proxy: {
    type: 'jsonp',
    url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
    reader: {
    type: 'json',
    rootProperty: 'responseData.feed.entries'
    }
    }
    }
    }
    ]
    });
    }
    });

    If you would please hilight in ORANGE where the callback is specified in the previous code...

    and to use your own words:

    "The server never care what callbackName is,it only care if there is a callbackKey in the request parameterMap."

    but the (Building your First App) never specifies a callback key to the server....
    in the example ther is NO "
    callbackKey in the request parameterMap"

    so how/why does it work?



  8. #7
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    Did I use the word 'default' wrong?The dictionary told me meaning of 'default ' is:
    Computer Science A particular setting or value for a variable that is assigned automatically by an operating system and remains in effect unless canceled or overridden by the operator.
    callbackKey has a default value ,which is 'callback'!
    Code:
    function foo(value){
        var default='bar';
        return value?value:default;
    }
    foo('hello');
    foo();//you think this will return null or '' or undefinded?
    
    function fun(config){
        var defaultValue='callback';
        config=config?config:{};
        if(!config.callbackKey){
            config.callbackKey=defaultValue;
        }
        alert(config.callbackKey);
    }
    fun({name:'a',callbackKey:'jsoncallback'});
    fun({name:'b'});
    Code:
    proxy: {
        type: 'jsonp',
        url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog',
        reader: {
             type: 'json',
             rootProperty: 'responseData.feed.entries'
        }
        //,callbackKey:'callback'    this is default value if you do not assign!
    }
    QQ截图20121031235306.png
    I write English by translator.

  9. #8
    Sencha User
    Join Date
    Oct 2012
    Posts
    5
    Vote Rating
    0
    cjones56 is on a distinguished road

      0  

    Default thank you very much

    thank you very much


    Yes , you used the word default correctly.

    When you said default I was thinking default function strictly on the client side...

    I did not realize that the default callback function was being appended to the url string as a default.

    I now understand.

    And I also see no why the server needs to respond appropriately.

    The picture of the headers was the answer for me. (I should have looked at that myself)

    Thank you very much

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar