how to get the server response.responseText after store load extjs 4
Asked Answered
S

6

7

I'm having one problem with getting the response.responseText from the server response in extjs 4.

Below is my code to load the store:

store.load({
    params: {
        'projectid': this.projectid
    },
    callback: function (records, operation, success, response) {
        console.log(records);
        console.log(response.responseText);
    }
});

Actually, when I made the request with the below function, I properly get the reponse.responseText.

Ext.Ajax.request({
    url: 'login/GetLoginCheck.action',
    method: 'GET',
    params: {
        'username': values['username'],
        'password': values['password']
        },
    scope: this,
    success: function(response) {
        Ext.Msg.alert(response.responseText);
        var redirect = response.responseText;
        window.location.href = "" + redirect + ".jsp";
    },
    failure: function(response) {
        Ext.Msg.alert('INVALID USERNAME OR PASSWORD');
    }
});

So please suggest me how can I get the response.responseText from the store.load() having a callback function.

Sloane answered 20/4, 2012 at 6:24 Comment(0)
F
8

callback has 3 parameters... try this :

store.load({
    params: {
        'projectid': this.projectid
    },
    callback: function (records, operation, success) {
        console.log(operation.response.responseText);
    }
});
Fluke answered 20/4, 2012 at 11:14 Comment(1)
I have no "operation.response" when the server returns 500. When server response the error message with status 500, I have to use Ext.Ajax.request to show the message and stacktrace.Muldon
V
1

I have faced a similar problem using Model.load(...), but in my case, operation.response was not defined. So, I have found another way to get it :

Model.load(1, {
    success: function () {
        // I haven't tested inside this callback yet
    },
    failure: function (record, operation) {
        var response = operation.request.proxy.reader.rawData;
        alert(response.message);
    }
});
Vatican answered 24/5, 2013 at 11:22 Comment(0)
L
1

You may also try this..

Ext.create('Ext.data.Store',{
    fields[],
    proxy:{url:'store_url.json', reader:{type:'json',root:'data'}},
    autoLoad:true,
    listeners:{
        load:function(store, record, success, opts){
            var response_text = store.proxy.reader.rawData;
            console.log(response_text);
        }
    }
})
Loyceloyd answered 1/4, 2014 at 4:0 Comment(1)
this is what im looking for. the response parameter in the callback function of store.load would be undefined if success == falseLorenzoloresz
D
0

In extjs 3.4 you can use this:

this.historyInvoiceHeaderGrid.store.load({
        params:{start:0, limit:20},
        callback: function (records, operation, success) {
            console.log(this.reader.jsonData);
        }});

This property store.reader.jsonData will return full response.

Maybe for someone it would be usefull in extjs 3.

Dufrene answered 21/11, 2013 at 6:46 Comment(0)
L
0

In Extjs 4.x it is working like this

myStore.load({
        url: 'myurl',
        method: 'GET',
        callback: function(records, operation, success) {
        var jsonStr = Ext.JSON.decode(operation.response.responseText);
            alert(jsonStr.message);
         }
});

In Extjs 5 you have to do like this

myStore.load({
        url: 'myurl',
        method: 'GET',
        callback: function(records, operation, success) {
 var message=forecastMethodStore.getProxy().getReader().rawData.message;
         }
});

But the key point here is you should set the message in JSON response from java side.

Sample: {"Root":[], "message":"duplicates"}"

Hope this will help someone.

Ladawnladd answered 18/3, 2015 at 15:42 Comment(1)
Using ExtJs 4.1.3 and i have no response on the operation.Wilterdink
L
0

You must set messageProperty in proxy reader in your 'Ext.data.Store'.

            reader: {
                type: 'json',
                root: 'myDataList',
                totalProperty: 'myTotalRecord',
                successProperty: 'mySuccess',
                messageProperty : 'myMsg'
            }

when mySuccess returns false then invoked callback: function.

    store.load({
        params: {start: 0, limit: 15},
        callback: function (records, operation, success) {
            if (!success) {
                try {
                    Ext.Msg.alert('Sorry !', operation.getError());
                    // operation.getError() returns myMsg value
                }catch (e){
                    Ext.Msg.alert('Exception !', e);
                }
            }
        }
    });

Here is a json return from Java Servlet.

    Map<String, Object> myDataMap = new HashMap<>(3);
    try {
        // Something
        myDataMap.put("mySuccess", true);
        myDataMap.put("myMsg", "Whats up khomeni !");
    } catch (Exception e) {
        myDataMap.put("mySuccess", false);
        myDataMap.put("myMsg", "Whats wrong with me.");
    }
    String json = new Gson().toJson(myDataMap);
Lanoralanose answered 2/1, 2017 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.