Last Comment Bug 311724 - JavaScript Console reports XML syntax error whenever XMLHttpRequest is used with an XML mime type and non-XML content
: JavaScript Console reports XML syntax error whenever XMLHttpRequest is used w...
Status: RESOLVED INVALID
: perf
Product: Core
Classification: Components
Component: XML (show other bugs)
: Trunk
: PowerPC Mac OS X
: -- normal (vote)
: ---
Assigned To: xml
: Ashish Bhatt
: Andrew Overholt [:overholt]
Mentors:
http://gene.sentinel3.phase.org/nsaja...
: 322120 342137 409230 438913 448347 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-10-08 16:05 PDT by wechsler
Modified: 2009-12-08 12:11 PST (History)
14 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Clean XHTML text case (853 bytes, text/html)
2005-10-08 16:07 PDT, wechsler
no flags Details
File called by ajax.html (2.24 KB, application/x-httpd-php-source )
2005-10-08 16:08 PDT, wechsler
no flags Details
Test case, copied from developer.mozilla.org example code (1.44 KB, text/html)
2005-10-08 16:12 PDT, wechsler
no flags Details
Used by nsajax.html (22 bytes, text/plain)
2005-10-08 16:13 PDT, wechsler
no flags Details
File called by ajax.html (22 bytes, application/x-httpd-php-source )
2005-10-08 16:17 PDT, wechsler
no flags Details

Description wechsler 2005-10-08 16:05:36 PDT
User-Agent:       Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b5) Gecko/20051006 Firefox/1.4.1
Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b5) Gecko/20051006 Firefox/1.4.1

Whenever an xmlHttpReq object is sent, an error appears in the javascript
console, which suggests that the javascript engine is trying to execute the
fetched page as javascript code.

Eg - for the above URL, taken from the mozilla developer area (info in example
page source):

Error: syntax error
Source File: http://gene.sentinel3.phase.org/test.txt
Line: 1, Column: 1
Source Code:
Hello World^

Similar problems occur at the URL http://gene.sentinel3.phase.org/ajax.html
which is a reduced case triggered from a clean HTML file.

False errors like this take a whole lot of wasted debugging time! 

The errors do not appear in Firefox 1.0.6 on the same machine.

Reproducible: Always

Steps to Reproduce:
1. Open and clear the Javascript console
2. Go to either of the above test URLs
3. Click the text
4. Clear the alert box (on the nsajax example)
5. Check the Javascript console for a new error

Actual Results:  
An error similiar to the following is flagged in the javascript console:
Error: syntax error
Source File: http://gene.sentinel3.phase.org/test.txt
Line: 1, Column: 1
Source Code:
Hello World^

Or, where an attempt is made to fetch a file containing only: 
'alert("Hello World");'
the error is
Error: not well-formed
Source File: http://gene.sentinel3.phase.org/test.txt
Line: 1, Column: 6
Source Code:
alert("Hello World");-----^


Expected Results:  
No error should have been flagged. In the nsajax.html case an alert box should
appear; in the ajax.html no result should be visible.

OSX 10.4.2
  Machine Name:	PowerBook G4 12"
  Machine Model:	PowerBook6,4
  CPU Type:	PowerPC G4  (1.2)
  Number Of CPUs:	1
  CPU Speed:	1.33 GHz
  L2 Cache (per CPU):	512 KB
  Memory:	768 MB
  Bus Speed:	167 MHz
Comment 1 wechsler 2005-10-08 16:07:51 PDT
Created attachment 198964 [details]
Clean XHTML text case

Calls test.php (uses POST method, required a PHP file on this server)
Comment 2 wechsler 2005-10-08 16:08:52 PDT
Created attachment 198965 [details]
File called by ajax.html
Comment 3 wechsler 2005-10-08 16:12:30 PDT
Created attachment 198966 [details]
Test case, copied from developer.mozilla.org example code

Taken from 
http://developer.mozilla.org/en/docs/AJAX:Getting_Started#Step_3_.E2.80.93_.22All_together_now.21.22_-_A_Simple_Example

as an example of known good code
Comment 4 wechsler 2005-10-08 16:13:25 PDT
Created attachment 198967 [details]
Used by nsajax.html
Comment 5 wechsler 2005-10-08 16:17:57 PDT
Created attachment 198968 [details]
File called by ajax.html

File 198965 was wrong file - uploaded in error!
Comment 6 Adam Guthrie 2005-10-08 16:55:10 PDT
I have a feeling this has something to do with how you're serving (or not having
a doctype or something in) text.txt.
Comment 7 Jesse Ruderman 2005-10-08 18:12:20 PDT
This line of the testcase tells Firefox to treat the response as XML:

        xmlHttpReq.overrideMimeType('text/xml');

When Firefox gets the response, it tries to treat it as XML and reports an XML
syntax error when it fails to parse it.  You can tell that this is an XML
parsing error rather than a JavaScript error by comparing the error messages
generated by these two data URLs:

        data:text/xml,report|OK
        data:text/html,<script>report|OK</script>

This could be fixed by:

A) Fixing the example on the wiki to not override the mime type.  (When is it
necessary to override the mime type?  Do you have to use an XML mime type to
make .responseXML work?)

B) Making Firefox not report XML syntax errors unless you use .responseXML.

C) Making Firefox not even try to parse the XML until you use .responseXML.

See also bug 302622, you're not the only person confused by this.

Bug 243089 might be related.
Comment 8 wechsler 2005-10-09 02:19:08 PDT
Thanks Jesse - I've created a couple of text cases where XML datatypes are not
overridden or set, (using text/plain instead). The error does not arise in this
case, in either Firefox 1.5b2 or 1.06 -

http://gene.sentinel3.phase.org/ajax2.html
http://gene.sentinel3.phase.org/nsajax2.html

This may mean that this is notabug in Firefox, but in the vast majority of AJAX
documentation online. I'll see what I can do about contacting people in charge
of such documentation.
Comment 9 Boris Zbarsky [:bz] (still a bit busy) 2005-10-09 06:26:30 PDT
I think it's reasonable to report an error when we're told to parse something as
XML and can't... If we didn't, it would be much much harder to debug cases where
eg the server is not returning what you think it is.

It sounds like the only real bug here is that the error console is still
misnamed "Javascript console".

As for when overriding the type is needed, it's needed any time you expect to
want the DOM and aren't sure the server will send the data with an XML type.
Comment 10 Jesse Ruderman 2005-10-09 16:21:00 PDT
Why does Gecko use the mime type (set by the server or a JavaScript override) to
determine whether to try to generate a DOM rather than, say, only generating the
DOM the first time the script actually accesses responseXML?  (See (C) in 
comment 7.)
Comment 11 Boris Zbarsky [:bz] (still a bit busy) 2005-10-09 17:31:31 PDT
I suspect this was done partly because it was easy to both pump data into the
parser and to stash in in our responseText.  But it also has the side benefit
that once an async XMLHttpRequest is done, getting the responseXML doesn't
freeze up while it tries to parse the whole thing.

Some data on how often people do or don't want the responseXML would also help
here.  If they usually want it, parsing eagerly is the way to go.
Comment 12 Jesse Ruderman 2006-01-02 14:12:50 PST
*** Bug 322120 has been marked as a duplicate of this bug. ***
Comment 13 Boris Zbarsky [:bz] (still a bit busy) 2006-04-18 21:49:15 PDT
This is invalid.
Comment 14 Dave Townsend [:mossop] 2006-06-22 05:49:56 PDT
*** Bug 342137 has been marked as a duplicate of this bug. ***
Comment 15 Sventek 2007-03-03 22:16:19 PST
can you try please with this : in text.txt ===> Test lève épaules ümläutö rêve ?

you can test it here :

http://maroc.flash.free.fr/httprequest_test.html
Comment 16 Philip Chee 2008-08-01 21:41:15 PDT
*** Bug 409230 has been marked as a duplicate of this bug. ***
Comment 17 Boris Zbarsky [:bz] (still a bit busy) 2008-08-19 21:53:14 PDT
*** Bug 448347 has been marked as a duplicate of this bug. ***
Comment 18 Boris Zbarsky [:bz] (still a bit busy) 2008-08-19 22:05:30 PDT
*** Bug 438913 has been marked as a duplicate of this bug. ***
Comment 19 John J. Barton 2009-12-08 12:11:20 PST
Just in case some else hits this...

If you execute a XHR from a file URL, the MIME mapping is different than a server URL. 
https://developer.mozilla.org/En/How_Mozilla_determines_MIME_Types#ExternalHelperAppService

So JS applications that work perfectly fine from a server generate the subject error message when run from the file system.

In our specific case we tried to load a dojo app from the filesystem for a test suite. Every dojo file load (lots of them) gives the error message.

To overcome this problem you have to explicitly set the MIME type
req.overrideMimeType('text/plain');

Note You need to log in before you can comment on or make changes to this bug.