Search code examples
javascriptasp.net-mvc-3moss

strange characters (amp;) added to moss service output


I have moss service which output the url of image.

Lets say the output url has '&' character , the service appending amp; next to &.

for ex: Directory.aspx?&z=BWxNK

Here amp; is additionally added. it is a moss sevice. so i don't have control on the sevice.

what i can do is decode the output. As i am using Ajax calls for calling moss sevice i am forced to decode the out put from javascript. i tried decodeURIComponent,decodeURI,unescape. nothing solved the problem.

Any help greatly appreciated. even server side function also helpful. i am using Aspl.net MVC3

Regards, Kumar.


Solution

  • & is not URI encoded, it's HTML encoded.

    For a server side solution, you could do this:

    Server.HtmlDecode("&") // yields "&"
    

    For a JavaScript solution, you could set the html to "&" and read out the text, to simulate HTML decoding. In jQuery, it could look like this:

    $("<span/>").html("&amp;").text(); // yields "&"