PDA

View Full Version : EXTJS4 - Ext.data.store POST data in JSON format issue



ermalex
3 Mar 2012, 9:49 AM
Hello

I'm trying to make EXT JSON store to send data using JSON, however I cannot figure out how to do it (it keeps sending parameters without conversion to JSON). Here is simple code:







var myStore = new Ext.data.Store({
//model: 'User',
proxy: {
type: 'ajax',
url: '/users.svc',
reader: {
type: 'json',
root: 'users'
},
writer: {
type: 'json',
root: 'data'
},
actionMethods: {
create: 'POST', read: 'POST', update: 'POST', destroy: 'POST'
},
extraParams: { test: 'test' }
},
listeners: {
beforeload: function (store, operation, options) {
//alert(operation.params);
}
},
autoLoad: true
});

Since I defined JSON "writer", my expectation that parameters would be send to server using JSON.
However it's still doing regular POST with following body:

test=test&page=1&start=0&limit=25
While my expectation is that POST should have the following body:
{test:'test',page:1,start:0}
I would appreciate any help
Thanks
P.S. I'm using EXTJS 4.0.7

Animal
3 Mar 2012, 10:48 AM
That's the load triggered by your autoLoad: true

ermalex
3 Mar 2012, 11:01 AM
That's the load triggered by your autoLoad: true
Yep. What I'm trying to do is to POST data in JSON format (irrespective what triggered the load). In my real app the load is triggered by ComboBox (which is attached to store). Currently the POST data is sent in the format "test=test&page=1&start=0&limit=25", while I'm trying to accompish "{test:'test',page:1,start:0,limit:25}" (in JSON format). Is there anyway I could accopmish this through store/proxy configuration (based on my understanding of APIs "writer" param in proxy is exactly for this, but it does not seem to be working.
Thanks

masoud_tamizy
4 Mar 2012, 12:33 AM
var userrealstore = Ext.create('Ext.data.Store', {
id:'userstore',
model: 'Real_User',
//autoLoad: true, // when i need this store , i call : userrealstore.load();
autoSync: true, // True to automatically sync the Store with its Proxy after every edit to one of its Records. Defaults to false.
proxy: {
type: 'ajax',
api:{
read: 'final/PHP/user_real/prepare.php',
//create:'PHP/user_real/create.php',
update: 'final/PHP/user_real/update.php',
destroy: 'final/PHP/user_real/destroy.php'
},
reader : {type:'json',root:'users',successProperty: 'success',messageProperty: 'message'},
writer : {type:'json',root:'users',writeAllFields: true/*,successProperty: 'success'*/},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
},
listeners: {
write: function(proxy, operation){
if (operation.action == 'destroy') {
Ext.example.msg(operation.action, "?????? ??? ????? ?? ?????? ????? ??");
}else if (operation.action == 'update') {
Ext.example.msg(operation.action, "?????? ????????? ?? ?????? ????? ??");
userrealstore.load();
}
}
}
});

ermalex
4 Mar 2012, 8:07 AM
var userrealstore = Ext.create('Ext.data.Store', {
id:'userstore',
model: 'Real_User',
//autoLoad: true, // when i need this store , i call : userrealstore.load();
autoSync: true, // True to automatically sync the Store with its Proxy after every edit to one of its Records. Defaults to false.
proxy: {
type: 'ajax',
api:{
read: 'final/PHP/user_real/prepare.php',
//create:'PHP/user_real/create.php',
update: 'final/PHP/user_real/update.php',
destroy: 'final/PHP/user_real/destroy.php'
},
reader : {type:'json',root:'users',successProperty: 'success',messageProperty: 'message'},
writer : {type:'json',root:'users',writeAllFields: true/*,successProperty: 'success'*/},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
},
listeners: {
write: function(proxy, operation){
if (operation.action == 'destroy') {
Ext.example.msg(operation.action, "?????? ??? ????? ?? ?????? ????? ??");
}else if (operation.action == 'update') {
Ext.example.msg(operation.action, "?????? ????????? ?? ?????? ????? ??");
userrealstore.load();
}
}
}
});


Hi Masoud
When I try you code, it's still does not convert parameters to JSON. It makes the following server call:
http://........./prepare.php?page=1&start=0&limit=25
I want it to be POST (which I know how to do) and I want query params to be in JSON format like {page:1,start:0,limit:25}

Thanks

PiyushOn
18 Feb 2015, 12:47 AM
I have same issue. How can i solve this.