Jez D
Jez D

Reputation: 1487

How do I get JSON data using Sencha

New to Sencha, I am using the following code to try to get JSON data. For some reason, it returns null, yet I know the URL is returning values, as I am using it in another project.

// Make the JsonP request
        Ext.data.JsonP.request({
            url: 'http://xxx.azurewebsites.net/login',
            crossDomain: true,
            type: "GET",
            dataType: "json",
            callbackKey: 'jsoncallback',
            callback: function(successful, data ) {
                alert( JSON.stringify(data) );
            }
        });

Can someone please point out what I am missing.

Upvotes: 0

Views: 3337

Answers (1)

Kunalan S
Kunalan S

Reputation: 154

You need to add scope:this property to call callback function, try like this.

Ext.data.JsonP.request({
    url: 'http://xxx.azurewebsites.net/login',
    crossDomain: true,
    type: "GET",
    dataType: "json",
    callbackKey: 'callback',
    scope: this,
    callback: function (response, value, request) {
        var result = Ext.decode(response.responseText);
        alert(result.propertyName);
    }
});

Upvotes: 1

Related Questions