PDA

View Full Version : Force store to load data via POST instead of GET



brittongr
16 Jul 2009, 12:15 PM
Hi everyone, before ext 3.0 i was loading my data calling an asp.net web service via POST just so:


var dsStore = new Ext.data.Store(
{
proxy: new Ext.ux.AspNetHttpProxy({
url: "DataServices.asmx/GetServices"
}),
reader: new Ext.data.JsonReader({
root: 'd',
id: 'ServiceId',
fields: [
{name: 'ServiceId'},
{name: 'Description'}
]
}),
remoteSort: false // Turn off remote sorting
});

but now im trying ext 3.0 and store.load(); is requesting the data via GET and i want to force it to do it by POST, i tried adding the method config option to HttpProxy and also the params option like and the params into the store.load() but it doesn't work for me.



var dsStore = new Ext.data.Store(
{
proxy: new Ext.ux.AspNetHttpProxy({
url: "DataServices.asmx/GetServices",
params:{Id:'<%= Id %>', Search:''},
method: 'POST',
}),
reader: new Ext.data.JsonReader({
root: 'd',
id: 'ServiceId',
fields: [
{name: 'ServiceId'},
{name: 'Description'}
]
}),
remoteSort: false // Turn off remote sorting
});

Does someone know how can i solve this??

Thanks for the help!

tryanDLS
16 Jul 2009, 1:43 PM
Seems that the doc for HttpProxy is not generating all the comments. Take a look at the source of HttpProxy regarding use of the api config. Instead of method try something like


api: {
load: {url: 'read.php', method: 'POST'}
}

mjlecomte
16 Jul 2009, 5:11 PM
Might be something with your proxy, I have no idea what that proxy is.

I toggled the following code between POST/GET without issue:


store = new Ext.data.JsonStore({
autoLoad: false,
baseParams:{
jelly:'bean'
},
proxy: new Ext.data.HttpProxy({
method: 'GET',
jsonData:{
id:1
},
url: 'test.php',
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}),
root: 'd', //the root node of the json object
id: 'id', //the record id
fields: ['id', 'name']
});
store.load();

brittongr
17 Jul 2009, 11:32 AM
Seems that the doc for HttpProxy is not generating all the comments. Take a look at the source of HttpProxy regarding use of the api config. Instead of method try something like


api: {
load: {url: 'read.php', method: 'POST'}
}




Ext.ux.AspNetHttpProxy = Ext.extend(Ext.data.HttpProxy, {
load: function(params, reader, callback, scope, arg) {
// JSON-encode parameters because ASP.NET requires that
params = Ext.util.JSON.encode(params);
Ext.ux.AspNetHttpProxy.superclass.load.call(this, params, reader, callback, scope, arg);
}
});

var dsStore = new Ext.data.Store({
proxy: new Ext.ux.AspNetHttpProxy(
{
api: {
load:{url:"DataService.asmx/GetServices", method:'POST'}
}
}),
reader: new Ext.data.JsonReader(
{
root: 'd',
id: 'ServiceId',
fields: [
{name: 'ServiceId'},
{name: 'Description'}
}),
remoteSort: false // Turn off remote sorting
});

With that firebug console give me this error:
TypeError: r.indexOf is not a function
http://localhost:64353/Scripts/ext-3.0/ext-all.js
Line 9

brittongr
17 Jul 2009, 11:37 AM
Might be something with your proxy, I have no idea what that proxy is.

I toggled the following code between POST/GET without issue:


store = new Ext.data.JsonStore({
autoLoad: false,
baseParams:{
jelly:'bean'
},
proxy: new Ext.data.HttpProxy({
method: 'GET',
jsonData:{
id:1
},
url: 'test.php',
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
}),
root: 'd', //the root node of the json object
id: 'id', //the record id
fields: ['id', 'name']
});
store.load();


I use that proxy (please see my previous post) because i need to send params as json format to the web service, and i tried your code changing "GET" to "POST" and still doing a GET request...

mjlecomte
17 Jul 2009, 1:15 PM
I use that proxy (please see my previous post) because i need to send params as json format to the web service, and i tried your code changing "GET" to "POST" and still doing a GET request...

ok, but that doesn't tell me what that proxy code is doing does it? As it turns out that code I posted is doing just that, posting json to the server, see the jsonData property?

Anyway, no one can help if they don't know what that hidden code is or is not doing.

brittongr
17 Jul 2009, 3:14 PM
Anyway, no one can help if they don't know what that hidden code is or is not doing.

No... i'm not hidden the code, this is only what the AspNetHttpProxy has, is and override of load, that's it...


Ext.ux.AspNetHttpProxy = Ext.extend(Ext.data.HttpProxy, {
load: function(params, reader, callback, scope, arg) {
// JSON-encode parameters because ASP.NET requires that
params = Ext.util.JSON.encode(params);
Ext.ux.AspNetHttpProxy.superclass.load.call(this, params, reader, callback, scope, arg);
}
});


Thanks...

mjlecomte
17 Jul 2009, 6:10 PM
load method of proxy is either deprecated or removed. To be more correct you should implement a doRequest() method if you want to override the proxy.

That said, I would still consider using what I said above where you use the jsonData param, that's what it is there for.

I believe to modify the encoded params you listen to beforeload/beforewrite and modify store.proxy.conn.jsonData as you need to.

rogerio.carrasqueira
22 Sep 2010, 6:40 AM
Hi!

I'm having the same problem, did you solved? Can you share your solution?

Thanks

troseberry
22 Sep 2010, 6:54 AM
I currently am using a proxy to get data from an ASP Based webservice. It returns XML. I am using the following with no issues. I just specify the "method". You can look at the Ext.Ajax.request() method it might help to.


proxy: new Ext.data.HttpProxy({
url: this.url,
method: 'POST',
headers: {
'SOAPAction': this.namespace + this.method,
'Content-Type': 'text/xml; charset=utf-8'
},
xmlData: this.buildSOAPPacket()
})