Re: Ampersands in JavaScript

On 18 Jul 2007, at 10:37, Peter Laudy wrote:
> I'm developing a web page, where I compose a URL in JavaScript and  
> then
> send it to the server using an XmlHttpObject (like you would when  
> using
> AJAX). This means that the URL is not processed by an HTML parser.

The ampersand character is inline in the document, so it is parsed by  
whatever parses the document. Since your document is served as text/ 
html, that is an HTML parser.

> If I
> use the & sign to add parameters to this URL, the page does not
> validate. If I use & the URL is not correct.

You are using XHTML and serving it as text/html, but not following  
the guidelines laid down in Appendix C of the XHTML 1.0 specification  
which explain how to write your XHTML in such a way as to be so close  
to HTML 4.01 that it can be parsed by HTML parsers (it also renders  
using XHTML pointless).

It is invalid when you use & because XHTML is different. It doesn't  
work when you use & because HTML parsers can't cope with that  
particular difference.


David Dorward

Received on Wednesday, 18 July 2007 19:21:46 UTC