PDA

View Full Version : Ext.data.proxy.Ajax not sending extraParams



gezb
24 Feb 2014, 1:25 PM
Hi. I have a number of stores in which I need to send extraParams to the backend database via JSON. I am trying to re engineer these stores to use a single proxy, but the extraParams are not being sent. I am using the MVC style for the application. Any hints would be appreciated. Thanks in advance. Code below

Ext.define('Contact.store.proxy.contactProxy', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.contactProxy',

proxy: {
type: 'ajax',
extraParams: {
"123":"456" // these do not get sent
}
},

reader: {
type: 'json',
messageProperty: 'msg',
root: 'data',
successProperty: 'success'
},

writer: {
type: 'json',
writeAllFields: true,
encode: true,
allowSingle: false,
root: 'data',
successProperty: 'success'
}
});


Ext.define('Contact.store.accounts.Accounts', {
extend: 'Ext.data.Store',
model: 'Contact.model.accounts.Accounts',


requires: [
'Contact.store.proxy.contactProxy'
],

storeId: 'Accounts',

proxy: {
type: 'contactProxy',
extraParams: {"ABC":"XYZ"}, // these get sent

api: {
create: 'php/accounts/addAccounts.php',
read: 'php/accounts/readAccounts.php',
update: 'php/accounts/updateAccounts.php',
destroy: undefined
},

actionMethods: {
create: "POST",
read: "POST",
update: "POST",
destroy: "POST"
}
}
});

skirtle
24 Feb 2014, 1:47 PM
Please use [CODE] tags when posting code.

You seem to be trying to configure another proxy on your proxy class. Theoretically it should be something like this:


Ext.define('Contact.store.proxy.contactProxy', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.contactProxy',

extraParams: {
"123": "456"
},

...
});

However, that won't work because the constructor for Ext.data.proxy.Server rather naively blows away the value on the prototype with the value from the instance config (I highly recommend taking a look at the source code to see what I mean). To set extraParams you'd have to override the constructor instead.


Ext.define('Contact.store.proxy.contactProxy', {
extend: 'Ext.data.proxy.Ajax',
alias: 'proxy.contactProxy',

constructor: function() {
this.callParent(arguments);

this.extraParams = {
"123": "456"
};
},

...
});

However, this gets trickier for shared proxies if the extraParams aren't all the same.

You might find this interesting as it covers some related material:

http://skirtlesden.com/articles/custom-proxies

gezb
24 Feb 2014, 2:23 PM
Thanks for your speedy reply and my apologies for not using code tags. I'm new to posting on Forums but will use the code tag in future. The link you provided is exactly what I am trying to do as the proxy configuration is the same over and over. In my case the extraParams names are always the same but the values may change. I'm sure I will be able to get this working after reading your page on Custom Proxies.

Thank you.