1

This would be my first website and I do not want to leave it these errors. Can someone please help me with these ones?

Error 1:

if (xmlhttp.readyState==4 && xmlhttp.status==200)

error: character "&" is the first character of a delimiter but occurred as data. WHEN i &, then my AJAX code stops working I have no clue how to correct this one.

Error 2:

…ems"><a href="brushdescription.php?id=<?php echo $popularbrushesrow['bd_brushi…

error: character "<" is the first character of a delimiter but occurred as data

Again the same error but for < this time

UPDATE: I am using this doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1
  • 2
    For the second error: Just put the processed HTML to the validator and not your PHP script and this error should vanish. For the first adding parenthesis might help, but not sure. Commented Jun 15, 2013 at 18:00

5 Answers 5

4

< and & are some of the predefined entities in XML, which need escaping when validating the page as XML or XHTML.

< should be replaced with &lt; (less than)

& should be replaced with &amp; (ampersand)

However, if using these characters in JavaScript you can (instead) enclose the script in a <![CDATA[]]> section, which instructs the parser to not interpret the code as markup and will also not result in a validation error.

Sign up to request clarification or add additional context in comments.

1 Comment

Replacing the & with &amp; in the JavaScript will break the script if the HTML document it is embedded in is served as text/html
2

Try wrapping your Javascript with <![CDATA[]]> tags like so:

<script>
  //<![CDATA[
    // Javascript goes here.
  //]]>
</script>

Also, you should look into separation of concerns. Try to move your logic out of you view. If your Javascript is in your HTML page, try to include it from a separate file.

From Wikipedia:

HyperText Markup Language (HTML), Cascading Style Sheets (CSS), and JavaScript (JS) are complementary languages used in the development of webpages and websites. HTML is mainly used for organization of webpage content, CSS is used for definition of content presentation style, and JS defines how the content interacts and behaves with the user. Historically, this was not the case though. Prior to the introduction of CSS, HTML performed both duties of defining semantics and style.

1 Comment

Better than wrapping JavaScript in CDATA, a modern DTD should be used, which is suited for HTML. I agree with the advice about separating the JS logic from the HTML.
0
  1. Use HTML, not XHTML (or, if you insist on using XHTML, see the guidelines on how to write XHTML that can be parsed as HTML).
  2. I can't see how you could have generated that error. Some more context would be useful.

Comments

0

For the first error, consider switching from XHTML to HTML5. There's really little reason to use XHTML. Use this:

<!DOCTYPE html>

The W3C validator is for client-side code, but it seems you are trying to validate server-side code, hence the PHP tag. Send the rendered code for validation and the second error will go away. The rendered code is the one visible in the browser under "View source". You can supply the URL if it's already online somewhere.

Comments

0

By XML rules, “The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " &amp; " and " &lt; " respectively.” So “&&” is to be written as &amp;&amp;.

However, this is such works only when the document is processed as “real XHTML” due to having been sent with an XML content type, e.g. with the HTTP header Content-Type: application/xhtml+xml. Doing so implies that old versions of IE will choke on it and modern browsers will refuse to render the document at all if it contains any well-formedness error. People don’t normally do that – they just use XHTML because someone told them to do so, and their documents are sent with an HTML document type, which means among other things that script element content is processed differently. This explains why a fix that satisfies the validator makes the page break.

In the XHTML 1.0 specification, the (in)famous appendix C says: “Use external scripts if your script uses < or & or ]]> or --.” This is the simple cure if you need to use XHTML. Just put your script in an external file and “call” it with <script src="foo.js"></script>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.