2

I am a little confused. I switched my content-type over to application/xhtml+xml on my server because I am using XHTML + some extra attributes (set with <!ATTLIST>). Since I did this, all hell broke loose.
For example, I have an autocomplete box that loads data from my server. The response from the server when an AJAX request is made is of application/json content-type. When the latter contains an ampersand in it, my browser shouts An invalid or illegal string was specified" code: "12. When I restore the content-type of my page to text/html, no error at all. I understand that an ampersand is represented differently in XHTML than it is in HTML, but the content type of the response is application/json, so why is jQuery trying to parse it as xhtml?
I have other similar errors throughout my code (all jQuery / javascript related).

What do I need to do to avoid these errors?

Ry-
  • 218,210
  • 55
  • 464
  • 476
Aviv
  • 75
  • 7
  • An ampersand is not represented differently in HTML and XHTML — it's `&` in both. – You Aug 12 '11 at 19:31
  • @You - That's not true at all. An ampersand may be sent as-is in HTML , depending on your text encoding scheme. In XHTML it has a special meaning, so must generally be wrapped in a CDATA block or entity encoded. – John Green Aug 12 '11 at 19:36
  • An ampersand cannot be sent as is, text encoding has no relevance because an ampersand only becomes an ampersand after decoding. In pcdata you can either quote it using CDATA, or by using & (and in attributes, you can only use &). – Remember Monica May 09 '13 at 23:48

1 Answers1

1

Possibly jquery is using the data sent as JSON and injecting in into the DOM using something like innerHTML. A page served as XML requires that the data supplied by innerHTML must also be XML conforming.

Alohci
  • 78,296
  • 16
  • 112
  • 156
  • that makes a lot of sense. that's probably why my code is failing in other places too, but what do I do to change this in jQuery? is there a XHTML/XML compliant version of jQuery? – Aviv Aug 12 '11 at 19:49
  • this is also causing a lot of troubles with my jQuery plugins. they are not working with the xhtml business.. is there away for me to fix this? – Aviv Aug 13 '11 at 01:18
  • @Aviv - There's no general solution, unfortunately. Too many plug-in authors simply don't take application/xhtml+xml into account. The only approaches are to (a) switch back to text/html or (b) go the whole hog with XML and seek out application/xhtml+xml compatible plug-ins or write you own JavaScript. – Alohci Aug 13 '11 at 09:08