View Full Version : Ext.urlEncode does not encode objects

16 Apr 2011, 8:09 AM
Dont know if this is a bug or a feature request...

But i noticed that
Ext.urlEncode({k1: 1, sub: {subk1: 1, subk2: 2}}) will produce

I need to add some extra data before submitting the form to the server.
I think the most clean way in my case, is to send it as a hash. Maybe is a good idea to make urlEncode produce

i.e. "k1=1&sub[subk1]=1&sub[subk2]=2.

Im using this, wich is working just for for me.


Ext.urlEncode = function(o, pre, keyPrefix){
var empty,
buf = [],
e = encodeURIComponent;

Ext.iterate(o, function(key, item){
empty = Ext.isEmpty(item);
Ext.each(empty ? key : item, function(val){
key = keyPrefix? keyPrefix + '['+key+']' : key;
if (Ext.isObject(item))
buf.push('&',Ext.urlEncode(item, pre, key))
else if (Ext.isArray(item))
item.forEach(function(i) {
buf.push('&', Ext.urlEncode(i, pre, key));
buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
pre = '';
return pre + buf.join('');

17 Apr 2011, 2:32 PM
That is quite interesting, what kind of server do you have that understands this format of query string?

What your doing is non-standard, so I thinks its unlikely support will be added. The IETF RFC on URI's clearly states that the 'query' portion of the URI cannot contain hierarchical data:


17 Apr 2011, 2:36 PM
Oh im not sure if its a standart..

I remember rails did use it like this.

Im currently using express (node), wich is working fine so far :)

17 Apr 2011, 4:33 PM
Interesting, ill have to check that out.