Seems like a very simple question here:
I've got a program where someone is entering a string M&S
in a form and running a query. I understand the &
is a reserved character and therefore must be encoded. The problem is it seems to be requiring encoding twice in some contexts.
If the URL is used in a javascript onClick
event, normal URL encoding seems to work fine (here the operator can click on a column header to sort):
<td onClick="AJAX_Get('http://10.0.0.195/program.exe?Qry147=M%26S&sortmethod1=161')">
However, if the URL is used in an anchor (although the anchor actually uses AJAX), it seems to need encoding twice:
<a href="javascript:AJAX_Get('http://10.0.0.195/program.exe?Qry147=M%2526S&sortmethod1=147')" title='Refresh'>Refresh</a>
Both of the examples above work fine. However they are hand-generated test cases. Unfortunately, in the application, when I'm actually generating the URL, I don't know how it's going to be used.
If I encode the URL parameter once (M%26S
), it works fine in onClick
. But used this way in the anchor, the server sees the URL as ...Qry147=M&S&sortmethod1=147...
- so it must have been unencoded before being given back to the server.
If I encode it twice (M%2526S
), the anchor works, but for the onClick
, the server sees ...Qry147=M%2526S...
.
I get the feeling I'm missing something here. Is there a way to make this work the same in both cases?