Closed Thread Icon

Topic awaiting preservation: The use of JavaScript encodeURI function (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8602" title="Pages that link to Topic awaiting preservation: The use of JavaScript encodeURI function (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: The use of JavaScript encodeURI function <span class="small">(Page 1 of 1)</span>\

 
Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 04-14-2003 20:00

I found out that if I'm using encodeURI function on string contains '&' character, it wont pass correctly to the server.
Example:
If the parameter value is virLocation7,Israel At&T
By using escape function we get: virLocation7%2CIsrael%20At%26T
By using encodeURI function we get: virLocation7,Israel%20At&T

I got the server parameter for the first case (escape) and it was correct (virLocation7,Israel At&T).
I got the server parameter for the second case (encodeURI) and it was partial (virLocation7,Israel At).

As far as I know we should replace the use of "escape" with "encodeURI" function.
Is there is a new way to send GET requests using parameter values contains "&"?

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-14-2003 20:44

Is this URI becoming the value of an HTML attribute at any point? For instance, are you creating the code

<a href="...AT&T...">...</a>

? If so, you must replace all ampersands (& with &amp;amp;

Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 04-14-2003 21:15

No.
I'm doing something like the following code:

function OpenURLWithParams(url, params){
url += "?";
for(var i=0; i<params.length; i++){
if(i > 0) url += "&";
url += params[i].key + "=" + encodeURI(params[i].value);
}

window.open(url);
}

Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 04-15-2003 17:43

I found it.
I have to use encodeURIComponent instead.

« BackwardsOnwards »

Show Forum Drop Down Menu