How to get .responseText server response after loading extjs 4 store

I am having one problem getting response.responseText from a server response in extjs 4.

Below is my code for loading 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 a request using the following function, I got 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 response.responseText from store.load () with a callback function.

+7
source share
6 answers

callback has 3 parameters ... try the following:

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

I ran into a similar problem using Model.load(...) , but in my case operation.response not defined. So, I 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); } }); 
+1
source

You can 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); } } }) 
+1
source

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 the full response.

Perhaps for someone this would be useful in extjs 3.

0
source

In Extjs 4.x, it works as follows

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 need to do 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 that you have to set the message in a JSON response from java. Example: "{\" Root \ ": [], \" message \ ": \" duplicates \ "}"

Hope this helps someone.

0
source

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

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

when mySuccess returns false , then callback: function called.

  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 the json answer 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); 
0
source

All Articles