Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ajax Programming

What's wrong with this rookie code?


Hi there -- I've been trying to get a basic XMLHttpRequest object to
read in XML from an XML file and it's not working. I'm sure there's
something really simple I'm just overlooking. I've been comparing it to
code I found on the web that definitely works and can't figure out what
the difference is aside from try catch statements (maybe that's it?).

Anyway, this is the code. Basically, I'm just trying to get an
acknowledgment that it actually read in XML from the file but Firefox
says the xmlDoc object is null... and while IE recognizes the object,
any processing I do on it fails.

Thanks for any help!

                function addMovies() {
                        var req = null;
                        if (window.XMLHttpRequest) {
                                req = new XMLHttpRequest();
                        } else {
                                if (window.ActiveXObject) {
                                        req = new ActiveXObject("Microsoft.XMLHTTP");
                                }
                        }
                        req.onreadystatechange = function() {
                                if (req.readyState == 4) {
                                        if (req.status == 200) {
                                                var xmlDoc = req.responseXML;
                                                window.alert(xmlDoc);
                                                document.getElementById("theClicker").disabled = true;
                                        } else if (req.status == 404) {
                                                window.alert("The requested URL does not exist!");
                                        } else {
                                                window.alert("Error: status code = " + req.status);
                                        }
                                }
                        };
                        req.open("GET", "ajaxtest.xml", true);
                        req.setRequestHeader("Content-Type", "text/xml");
                        req.send(null);
                }

Read this:

http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html

Eric

On 11/17/06, The alMIGHTY N <natle@yahoo.com> wrote:

Hi Eric,

Thanks for the response! I visited the URL you posted but still cannot
figure out what the problem is. Please forgive my ignorance:

a) Did you set your content type to text/xml?

I think so. Isn't that what the line
"req.setRequestHeader("Content-Type", "text/xml");" is supposed to do?
Do I need to somehow do this in the actual XML file itself?

b) Is your request actually making it to the server and back?

I tested out the script with some window alerts for the status - the
correct status code of 200 is going through...

c) When you alert/examine the responseText, do you see anything that
does not belong?

I'm opening a static XML file that I checked for syntax using Internet
Explorer. I think that should cover this point... or am I missing
something?

d) Open up the dynamic XML document in your browser directly. (Type the
url into the browser. This may require you to hard code post parameters
or build a test form.) The browser will tell you if your XML is not
formatted correctly. Is it formatted correctly?

See the answer to c. :-D

This is really confusing me. Is it possible that perhaps the server is
not set up to serve up XML documents? Is there some sort of special
setting in Weblogic that enables delivery of XML documents?

It's really strange... Even though I'm explicitly opening an XML file
and the content-type is being set to text/xml (as far as I know), the
response headers keep coming back with a content-type of text/plain.
Should this tell me something?

Thanks!

NL

It sounds like perhaps the MIME type of the response is not correct. The XML
object will be NULL if your response is something such as "text/plain". Make
sure your MIME type is either:   application/xml or text/xml

Hope that helps,
-Todd

On 11/20/06, The alMIGHTY N <natle@yahoo.com> wrote:

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc