-
3 Mar 2012 9:49 AM #1
Unanswered: EXTJS4 - Ext.data.store POST data in JSON format issue
Unanswered: EXTJS4 - Ext.data.store POST data in JSON format issue
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:
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:
While my expectation is that POST should have the following body:Code:test=test&page=1&start=0&limit=25
I would appreciate any helpCode:{test:'test',page:1,start:0}
Thanks
P.S. I'm using EXTJS 4.0.7
-
3 Mar 2012 10:48 AM #2Sencha - Ext JS Dev Team
- Join Date
- Mar 2007
- Location
- Notts/Redwood City
- Posts
- 30,459
- Vote Rating
- 18
- Answers
- 9
That's the load triggered by your autoLoad: true
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
3 Mar 2012 11:01 AM #3
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
-
4 Mar 2012 12:33 AM #4
sample store
sample store
Code: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(); } } } });
-
4 Mar 2012 8:07 AM #5
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


Reply With Quote