PDA

View Full Version : overide Ext.urlEncode



vahid4134
12 Nov 2009, 2:19 AM
Ext.urlEncode({foo: "1", bar: ["2", "3", "4"]});

In Extjs this code retrun foo=1&bar=2&bar=3&bar=4
but this return not a valid url for array

but in my code


Ext.urlEncode=function(o,pre,b){
var undef, buf = [], key, e = encodeURIComponent;
if(Ext.isArray(o)){
for(key=0;key<o.length;key++){
if(Ext.isPrimitive(o[key])){
buf.push("&", (b)?b+"["+ e(key)+"]":e(key) , "=", e(o[key]));
}
else{
buf.push("&", Ext.urlEncode(o[key],pre,(b)?b+"["+ e(key)+"]":e(key)));
}
}
}
else{
for(key in o){
if(Ext.isPrimitive(o[key])){
buf.push("&", (b)?b+"["+ e(key)+"]":e(key) , "=", e(o[key]));

}
else{
if(!Ext.isFunction(o[key])){
buf.push("&", Ext.urlEncode(o[key],pre,(b)?b+"["+ e(key)+"]":e(key)));
}
}


}
}



if(!pre){

buf.shift();

pre = "";

}

return pre + buf.join('');
}


top code return
foo=1&bar[0]=2&bar[1]=3&bar[2]=4

and in cdoe


Ext.urlEncode({foo: "1", bar: [foo1:{foo2:"3"}]})

return
foo=1&bar[foo1][foo2]=3

This is better?

vahid4134
14 Nov 2009, 11:23 PM
Thanks for move back

vahid4134
14 Dec 2009, 11:23 AM
If any problem report my.
In my opinion this is better than orginal Ext.urlEncode

davitz38
16 Jan 2010, 3:15 AM
Hi guys,
in case some you guys need to encode a url, try this online url encoder (http://www.stringfunction.com/url-encode.html)
David

vahid4134
16 Jan 2010, 10:25 AM
hi davitz38
but my code convert array or object to url