Question

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.

Was it helpful?

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 "&"

OTHER TIPS

&amp; is SGML/XML/HTML for &.

If the service is outputting an XML document, then make sure you are using an XML parser to parse it (and not regular expressions or something equally crazy).

Otherwise, you need decode the (presumably) HTML. In JavaScript, the easiest way to do that is:

var foo = document.createElement('div');
foo.innerHTML = myString;
var url = foo.firstChild.data;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top