Is the validator at fault? I wrote a script that grabs quite a bit of data to pass as post data to a PHP script via ajax. When I tried to validate the page, I got all kinds of errors about ampersand entities. Obviously, replacing them with & will make the data request NOT work, so is this a fault with the validator (i.e. the document IS valid) or is there some other way I should be doing this? Here's a mini-example with GET: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Validator Test</title> <script type="text/javascript"> var exampleGetString; exampleGetString = "?somedata=1"; exampleGetString += "&failedvalidation=1"; </script> </head> <body> </body> </html> HTML:
It's kinda your fault. As xhtml, you need to declare the script to be cdata. <script type="text/javascript"> //<![CDATA[ var exampleGetString; exampleGetString = "?somedata=1"; exampleGetString += "&failedvalidation=1"; //]]> </script> Code (markup): The browser doesn't care, because it's treating the doc as html, but the validator takes you at your word. Even if validating html, it's probably a good idea to enclose the script within comment tags. Not sure on the last, as I haven't written an html page in ages. cheers, gary