Friends, I am currently using the below function
to encode
my data and send them through GET
method... I am using ajax
to send and php
to receive them...
function urlencode(a){
a=encodeURIComponent(a);
a=a.replace(/\\/g,'%5C');
a=a.replace(/!/g,'%21');
a=a.replace(/'/g,'%27');
a=a.replace(/\(/g,'%28');
a=a.replace(/\)/g,'%29');
a=a.replace(/\*/g,'%2A');
a=a.replace(/~/g,'%7E');
a=a.replace(/%20/g,'+');
a=a.replace(/%26amp%3B/gi,'%26');
a=a.replace(/%26lt%3B/gi,'%3C');
a=a.replace(/%26gt%3B/gi,'%3E');
a=a.replace(/%26nbsp%3B/gi,'%C2%A0');
return a;
}
after passing the string through encodeURIComponent()
, I used extra replace()
method so that the function encode the string for my link as similar as php
...
Now my question is do anyone know any shorter or easy alternative way to do the same thing...
I place this question only for learning purpose... no jQuery please...