1. #1
    Ext JS Premium Member
    Join Date
    Oct 2008
    Posts
    8
    Vote Rating
    0
    ermalex is on a distinguished road

      0  

    Default 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:
    Code:
    test=test&page=1&start=0&limit=25
    While my expectation is that POST should have the following body:
    Code:
    {test:'test',page:1,start:0}
    I would appreciate any help
    Thanks
    P.S. I'm using EXTJS 4.0.7

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Answers
    13
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    That's the load triggered by your autoLoad: true

  3. #3
    Ext JS Premium Member
    Join Date
    Oct 2008
    Posts
    8
    Vote Rating
    0
    ermalex is on a distinguished road

      0  

    Default


    Quote Originally Posted by Animal View Post
    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

  4. #4
    Sencha User masoud_tamizy's Avatar
    Join Date
    Oct 2011
    Posts
    108
    Answers
    1
    Vote Rating
    0
    masoud_tamizy is on a distinguished road

      0  

    Default 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();
    				}
                }
    		}
    	});

  5. #5
    Ext JS Premium Member
    Join Date
    Oct 2008
    Posts
    8
    Vote Rating
    0
    ermalex is on a distinguished road

      0  

    Default


    Quote Originally Posted by masoud_tamizy View Post
    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();
                    }
                }
            }
        });
    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

Thread Participants: 2

Tags for this Thread