简体   繁体   中英

Extjs how to parse jsonP response

Using Ext5 I am trying to send a jsonp request to http://jsonplaceholder.typicode.com/posts .

This is my store:

Ext.define('MyApp.store.example.Post',
{
        storeId: 'Post',
        model: 'MyApp.model.example.Post',
        proxy:
        {
                type: 'jsonp',
                url: 'http://jsonplaceholder.typicode.com/posts',
                noCache: false,
                pageParam: false, // to remove param "page"
                startParam: false, // to remove param "start"
                limitParam: false, // to remove param "limit"
        },
        autoLoad: true
});

Using Fiddler Web Debugger I can inspect the http request/response. The url request is: http://jsonplaceholder.typicode.com/posts?callback=Ext.data.JsonP.callback1

You can inspect the response using the above url. My problem is how to parse the response from the server.

It looks like the _dc parameter for caching is causing the issue from what i can tell from your url endpoint.

You do not need to parse the JsonP request that is handled for you in the methods.

Here is a simple example of a Ext.data.JsonP.request that is functioning. And a fiddle of the working example .

Ext.data.JsonP.request({
        'url': 'https://jsonplaceholder.typicode.com/posts',
        disableCaching : false,
        success: function (result, request) {
            //success
            console.log(result, request);
        }
    });

Sencha docs is a great resource, here is the link to the JsonP doc regarding the caching. If you turn this property back to true you'll see that no results are returned from your endpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM