Results 1 to 9 of 9

Thread: Javascript usage of DOM with IE

  1. #1
    Join Date
    Oct 2006
    Location
    Silicon Valley
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript usage of DOM with IE

    I am trying to use the ajaxroutine.js routines. If I use FireFox, everything works great. If I use IE, the responseXML never shows up. The responseText is ok on either browser. I am using IE 7.0 and have tried earlier versions as well. My code is the following:

    function processUpdateMenu(){
    var myajax=ajaxpack.ajaxobj;
    var myfiletype=ajaxpack.filetype;
    if (myajax.readyState == 4){ //if request of file completed
    if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful
    if (myfiletype=="txt") {
    alert(myajax.responseText + "--text");
    }
    // No matter what I put in as the tag name, I always get nothing on IE
    var x = myajax.responseXML.getElementsByTagName("xmlresponse");
    // the next line returns nothing on IE, an object on FireFox
    alert("xml--" + myajax.responseXML);
    alert("length: " + x.length ); --- this is always 0 on IE

    Any ideas would be appreciated

    chas

  2. #2
    Join Date
    Oct 2006
    Location
    Silicon Valley
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The website is www.wineryearth.com. If you use FireFox, the menus all work, if IE, they don't.

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Your server-side code is returning data marked as HTML (text/html), not XML (application/xml or text/xml - preferably the former). Edit your PHP code to include a header function call that sets the Content-Type HTTP header.

    In case you were wondering: Firefox shows no apparent problems because you were overriding the MIME type with the overrideMimeType method. You should never need to call that: if the wrong MIME type is sent, the problem should be solved at the server.

    Hope that helps,
    Mike

  4. #4
    Join Date
    Oct 2006
    Location
    Silicon Valley
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried adding the header, but it didn't help. I added this to the php:

    <meta http-equiv="Content-Type" content="application/xml; charset=ISO-8859-1" />

    Is that the right thing to add. If you go to www.wineryearth.com and click on the continent menu you will see the xml that is being returned as text, and then the fact that xml is empty

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is that the right thing to add.
    No. Change the Content-Type header, don't use a <meta> tag, which is overridden by the header (and has no effect in XML anyway).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by scrapmetalca
    <meta http-equiv="Content-Type" content="application/xml; charset=ISO-8859-1" />

    Is that the right thing to add.
    What Twey said: no. As I wrote in my post, you need to use the PHP header function. Headers are part of the HTTP protocol, sent before the content generated by your code[1]. You need to include:

    Code:
    header('Content-Type: application/xml');
    You can add a character encoding (charset) parameter, though you might want to consider UTF-8 (the default for both XML and XMLHttpRequest) over ISO-8859-1. Either way, make sure that the parameter is accurate.

    As Twey also mentioned, meta elements containing content type hints are ignored in XML. Indeed, the only things that will care about these even in HTML are browsers, yet they are not the only interested parties. The Web is built on top of the Internet, and you, the developer, have no idea what lies between your server and your visitors. Caching servers and gateways may be very interested in this sort of metadata, which is why it should be the server that sets it.

    If you aren't familiar with HTTP, and you intend to work with server-side languages, then, in my opinion, you really should become aquainted the protocol. The specification (RFC 2616) is quite readable, and you can probably find other primers on the Web to help you along (though 2616 really is mandatory reading, in the end).

    Mike


    [1] Hence the header function needs to be called before your code starts writing data to the output stream (unless output buffering is used). If the header function is called later, a warning will be generated.

  7. #7
    Join Date
    Oct 2006
    Location
    Silicon Valley
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I changed my php to look like the following: (with some stuff removed)
    So now the header is the first thing. Works fine in FireFox, but still not in IE.
    I still don't get any xml back to IE.
    Any other ideas?

    <?
    header('Content-Type: application/xml');
    $search=$_POST['searchlocale'];

    function getData($data) {
    $data = "<hello />\n";

    return $data;
    }
    ?>
    <xmlresponse>
    <search><? echo $appelation ?></search>
    <data><? echo getData($data) ?></data>
    </xmlresponse>

  8. #8
    Join Date
    Oct 2006
    Location
    Silicon Valley
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    And I do appreciate all the help

  9. #9
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Not offhand, no. I can't reproduce the behaviour. If I have PHP return an XML document without setting the Content-Type header, MSIE exposes an empty XML document. If I add the header function call, the document contains all of the elements it should.

    You'll need to post the source code for a testable demonstration, though you should also check your server logs (if you haven't already) and double check the response headers to ensure that the Content-Type header has in fact been set properly, first.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •