PDA

View Full Version : AjaxProxy 'POST' method ?!



AndreaCammarata
14 Oct 2010, 7:33 AM
Hi guys, just a simple question:
Is it possible load server side json data using 'POST' method of an AjaxProxy used as part of a JsonStore?
I tryed to set:



...
method: 'post'
...


in my AjaxProxy and i can see by firebug that the request is correctly directed to the server but always in 'GET' mode.
The JsonStore and Proxy I'm using is exactly the same I use in another Ext page.
Using it on Ext page instead Sencha it correctly works!
The documentation doesn't list "method" as a config param for sencha AjaxStore, so I suppose it is not allowed.
Any idea?

Thank you guys

edspencer
14 Oct 2010, 10:23 AM
Hi Andrea,

I'm working on improving support for this proxy at the moment, it should be a lot more flexible in the next release

AndreaCammarata
14 Oct 2010, 10:36 AM
Hi edspencer and thank you for your support, i will waiting next releases then.
So, do you confirm that at the moment there is not a way to make a post request, even with the 0.97 version?

edspencer
14 Oct 2010, 10:39 AM
Actually, looking at the code now it seems that's already supported. You can just set the actionMethods property of your Proxy - I don't know how you're currently setting up your proxy but it would be something like this:



Ext.regModel('User', {
fields: ['id', 'name'],

proxy: {
type: 'ajax',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
}
}
});

AndreaCammarata
14 Oct 2010, 11:30 AM
Perfect edspencer, in the way you suggest me it perfectly works!
I edited my code from the Ext version that is:



myStore = new Ext.data.JsonStore({
storeId: 'myStore',
remoteSort: true,
proxy: new Ext.data.HttpProxy({
method: 'POST',
url: 'my_url.php'
}),
totalProperty: 'totalCount',
root: 'list',
baseParams: {
action: 'my_action',
start: 0,
limit: 16
},
...


to the sencha versione in the following way:


myStore = new Ext.data.JsonStore({
storeId: 'myStore',
remoteSort: true,
proxy: {
type: 'ajax',
url: 'my_url.php',
actionMethods: {
read: 'POST'
},
extraParams: {
action: 'my_action',
start: 0,
limit: 16
}
},
totalProperty: 'totalCount',
root: 'list',
...


Thank you again ed!

Mis63
14 Oct 2010, 11:02 PM
Hi ! I have too troubles with AjaxProxy to save data (read data from proxy works perfectly).
I create a store that contains some messages written by the user in my sencha application :


var sendStore = new Ext.data.JsonStore({
model: 'Message',
storeId: 'sendbox',
proxy: {
type: 'ajax',
url: 'MessageProxy', // It's URL of a Java servlet
extraParams: {
folder: 'sendbox'
},
reader: {
type: 'json',
root: 'messages',
idProperty: 'id'
},
writer: {
type: 'json',
root: 'messages'
}
},
autoLoad: true
});
Then I have a subclass of FormPanel where user can write its message, and send it. Here is the code of the send button which is an member of my subclass FormPanel :


onSend: function() {
var m, values, store;

// Fill the Message record with data entered by user in FormPanel
values = this.getValues();
m = this.getRecord();
m.set('id', 9999);
m.set('to', values.to);
m.set('subject', values.subject);
m.set('text', values.text);

// Add it to store and save it
store = Ext.StoreMgr.lookup('sendbox');
store.add(m);
store.sync();
}
The above code works fine, but the problem is about data received by my servlet proxy. The POST method is called twice consecutively, whereas there is only one message in the store.
Here is data received by my servlet (Ajax proxy) :
1. First call
URL & query string :
MessageProxy[POST] : /mobitouch/MessageProxy : _dc=1287124076830&folder=sendbox
Parameters :
folder : sendbox
_dc : 1287124076830
Body
{"messages":[{"id":9999,"date":null,"from":"","to":"CF","subject":"test","text":"bla bla bla","new":false,"read":false}]}

2. Second call
URL & query string :
MessageProxy[POST] : /mobitouch/MessageProxy : _dc=1287124077865&folder=sendbox
Parameters :
folder : sendbox
_dc : 1287124077865
Body :
{"messages":[{"id":9999,"date":null,"from":"","to":"CF","subject":"test","text":"bla bla bla","new":false,"read":false}]}

The servlet is called twice with exactely the same parameters. I think that it's because creations and modifications are bad detected in store, so record is sent first time as create opration, and second time as update operation.