views:

2390

answers:

2

Hi, is there a way to attach jsondata to a POST request for loading a store? I know it's possible through a GET request by simply adding params : {data1 : 1, data2 : 2} on the load call, but I've had no success attaching jsondata. I've tried the following and a few variations of it and no luck. I'm using Extjs 2.2 w/ Alfresco

//create store
        var memberStore = new Ext.data.JsonStore({
            proxy : new Ext.data.HttpProxy({
                url : url/getMembers,
                method : 'POST'
            }),
            fields : ['username'],
            root : 'members'
        });

//function that loads store when it is called
    function getMembers() {

        memberStore.load({
            //params : {action : "getmembers", groupname : "GROUP_Test"}
            jsonData : {
                action : "getmembers",
                groupname : "GROUP_Test"    
            }
        }); 
    }
A: 

Hi there,

You can use baseParams: { key: "value", key2: "value2" }

This should work with the store using both GET and POST.

JuanD
Hi Juan,Sorry for such a late reply. Unfortunately, baseParams would not work for me as the params would change. What I ended up doing was just create running an Ajax Request ( Ext.Ajax.Request({}) ) and load the store on a success return.
Snowright
Oh, I see.. That was an important detail.. Glad you found a solution :)
JuanD
Could you post an answer to your own question please? thx :)
JuanD
Hi Juan, thanks again for your reply, as requested, I've posted my solution. Cheers!
Snowright
A: 

Instead of calling a store.load(), I created a function that would run an ajax request for the data. On a successfull callback, I would then load the store. Below is my code.

//create store
var memberStore = new Ext.data.JsonStore({
        fields : ['username'],
        root : 'members'
    });

//function that loads store when it is called 
function getMembers() {

    var parameters = {
       node : dynamicNodeId  
    }

    Ext.Ajax.Request({
      url : 'url/getMembers',
      method : 'POST',
      jsonData : Ext.encode(parameters),
      success : function(response, opts) {
        //decode json string
        var responseData = Ext.decode(response.responseText);

        //Load store from here
        memberStore.loadData(responseData);
      }
  }); 

}//eo getMembers
Snowright