PDA

View Full Version : POST/Get How to



Mango_lier
26 Oct 2007, 1:52 PM
I have few quick questions as I am learning this toolkit.
If I am reading the documentation correctly, if

tryanDLS
26 Oct 2007, 2:00 PM
Yes, but you can override by passing method:'GET' or 'POST' as part of the Connection config to the proxy. Also in the next release support has been added for PUT.

Mango_lier
26 Oct 2007, 2:16 PM
What I am seeing is that when the "params" are present then method:'GET' is ignored and a POST request is made to the server.

Line 180 in connection.js is doing this:

var method = o.method||this.method||(p ? "POST" : "GET");

tryanDLS
26 Oct 2007, 2:33 PM
Maybe the changes mentioned here http://extjs.com/forum/showthread.php?t=15717 were not incorporated. However the current code should still see the method config passed in. Set a BP in Connection.Request and see what's passed in.

Mango_lier
26 Oct 2007, 2:43 PM
The method is "GET" till it reaches Line 180 in connection.js then it is changed to POST.

Animal
27 Oct 2007, 12:09 AM
That line won't change anything.

It sets the variable to the "method" property of the config parameter.

Unless that is not specified, in which case it uses the Ext.Ajax object's method property (which is not specified by default).

If it still can't find a value, then it looks if tere are params to see which to use.

If you pass method:'GET', in the config parameter it will use it.

Mango_lier
27 Oct 2007, 6:18 AM
You can try a simple experiment, using the paging grid example set the method property to GET and then see if it makes a GET request.

If I am reading it correctly, if anything is encoded in p then the call will always be a POST. I think it is a bug.


var method = o.method||this.method||(p ? "POST" : "GET");

if(method == 'GET' && (this.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
url += (url.indexOf('?') != -1 ? '&' : '?') + '_dc=' + (new Date().getTime());
}

if(typeof o.autoAbort == 'boolean'){
if(o.autoAbort){
this.abort();
}
}else if(this.autoAbort !== false){
this.abort();
}
if((method == 'GET' && p) || o.xmlData){
url += (url.indexOf('?') != -1 ? '&' : '?') + p;
p = '';
}
this.transId = Ext.lib.Ajax.request(method, url, cb, p, o);

tryanDLS
27 Oct 2007, 6:40 AM
The paging example is using ScriptTagProxy, so that's not a good test. Try it with the xml grid example. Modify the store config as follows: Note that if you want to configure the proxy beyond just passing an url, you have to declare the proxy, store doesn't pass anything but url in the simple case.



// create the Data Store
var store = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'sheldon.xml', method:'POST'}),

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'Item',
id: 'ASIN',
totalRecords: '@total'
}, [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'Author', mapping: 'ItemAttributes > Author'},
'Title', 'Manufacturer', 'ProductGroup'
])
});

Mango_lier
27 Oct 2007, 6:46 AM
This is how I am setting up my store. am I missing something? With paging enabled the call will end up as POST start, limit parameters


ds = new Ext.data.Store({
autoLoad: false,
method: 'GET',
url: 'http://localhost/ExtTest/Backend/Contacts_list.asp?xml=1',

// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Item" tag
record: 'Row',
id: 'ID',
totalRecords: '@TotalRecords'
}, [
// set up the fields mapping into the xml doc
'Name', 'Address', 'City', 'Phone', 'Email', 'Website'
])
});

tryanDLS
27 Oct 2007, 7:14 AM
Read my previous post.

Mango_lier
27 Oct 2007, 7:20 AM
Thanks tryanDLS, much better it solved the problem.

What is the difference between my previous code and your snippet.

Animal
27 Oct 2007, 7:49 AM
You can try a simple experiment, using the paging grid example set the method property to GET and then see if it makes a GET request.

If I am reading it correctly, if anything is encoded in p then the call will always be a POST. I think it is a bug.



var method = o.method||this.method||(p ? "POST" : "GET");


You are not reading it correctly.

That line sets the method variable to o.method.

If that was not specified, then it sets it to this.method.

If that was not specified, then it looks for parameters to decide.

This is how javascript's || operator works.

There is no problem in Ext.data.Connection.

Mango_lier
27 Oct 2007, 8:01 AM
agree

tryanDLS
27 Oct 2007, 8:05 AM
Thanks tryanDLS, much better it solved the problem.

What is the difference between my previous code and your snippet.

As I said in that post, my code passes the config to proxy, whereas yours passes it to store, which is ignored.

Mango_lier
27 Oct 2007, 8:17 AM
Thanks