xmlhttp problem using Mozilla ... responseText is always null

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fochie

    #1

    xmlhttp problem using Mozilla ... responseText is always null

    Greetings,

    I'm having a problem when I try to GET a file from my server
    via xmlhttp when using Mozilla. With IE I can get any type of file
    fine, get/display headers fine, etc. With Mozilla, using the same
    HTML/JS it always returns no data (xmlhttp.respon seText is null).

    When I try to get headers using Mozilla or display the http status code
    I get some obscure exception in the javascript console that I've given
    up on searching for an answer to ....

    Error: [Exception... "Component returned failure code: 0x80040111
    (NS_ERROR_NOT_A VAILABLE) [nsIXMLHttpReque st.status]" nsresult:
    "0x80040111 (NS_ERROR_NOT_A VAILABLE)" location: "JS frame ::
    http://myserver.com/xmlhttp.html? :: RSchange :: line 26" data: no]
    Source File: http://myserver.com/xmlhttp.html?
    Line: 26

    I've tried coding my test app many ways based on the examples out there
    and haven't been able to get it to run in Mozilla/FF yet.

    If I do an alert on xmlhttp.respons eText I get a blank alert pop up, if
    I alert xmlhttp.respons eText.length it's always zero using Mozilla.
    Both alerts always work with the same HTML/JS when running in IE.

    Beginning to think maybe I'm lacking something on the server side
    related to Content-type being sent back that IE allows and Mozilla
    doesn't(?)

    Any assistance at this point would be greatly appreciated.

    Thanks !
    Steve

    Here's a simple example that works in IE but returns null for
    responseText in Mozilla when I run it ...

    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JAVAS CRIPT" type="text/javascript">
    <!--
    var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_vers ion >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE
    versions.
    // and security blocked creation of the objects.
    try {
    xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
    } catch (E) {
    xmlhttp = false;
    }
    }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest! ='undefined') {
    xmlhttp = new XMLHttpRequest( );
    }

    function RSchange() {
    if (xmlhttp.readyS tate==4) {
    //if (xmlhttp.status == 200) {
    //alert(xmlhttp.s tatusText); // this line chokes in Mozilla
    alert(xmlhttp.r esponseText); //empty alert box using Moz
    // }
    }
    }

    function go() {
    if (xmlhttp) {
    xmlhttp.open("G ET", "http://myserver.com/index.html", true);
    xmlhttp.onready statechange=RSc hange;
    xmlhttp.send(nu ll);
    }
    }
    //-->
    </script>

    </head>
    <BODY>

    <FORM NAME='' ACTION='' onsubmit="retur n true;">
    <INPUT TYPE="SUBMIT" VALUE='getit' onclick="go()"
    </FORM>

    </BODY>
    </HTML>

  • Martin Honnen

    #2
    Re: xmlhttp problem using Mozilla ... responseText is always null



    fochie wrote:

    [color=blue]
    > I'm having a problem when I try to GET a file from my server
    > via xmlhttp when using Mozilla. With IE I can get any type of file
    > fine, get/display headers fine, etc. With Mozilla, using the same
    > HTML/JS it always returns no data (xmlhttp.respon seText is null).
    >
    > When I try to get headers using Mozilla or display the http status code
    > I get some obscure exception in the javascript console that I've given
    > up on searching for an answer to ....
    >
    > Error: [Exception... "Component returned failure code: 0x80040111
    > (NS_ERROR_NOT_A VAILABLE) [nsIXMLHttpReque st.status]" nsresult:
    > "0x80040111 (NS_ERROR_NOT_A VAILABLE)" location: "JS frame ::
    > http://myserver.com/xmlhttp.html? :: RSchange :: line 26" data: no]
    > Source File: http://myserver.com/xmlhttp.html?
    > Line: 26[/color]

    Which line exactly is that line 26, how does the code in that line look
    when you get that error message?
    Are you using frames or popup windows?
    [color=blue]
    > I've tried coding my test app many ways based on the examples out there
    > and haven't been able to get it to run in Mozilla/FF yet.
    >
    > If I do an alert on xmlhttp.respons eText I get a blank alert pop up, if
    > I alert xmlhttp.respons eText.length it's always zero using Mozilla.
    > Both alerts always work with the same HTML/JS when running in IE.
    >
    > Beginning to think maybe I'm lacking something on the server side
    > related to Content-type being sent back that IE allows and Mozilla
    > doesn't(?)
    >
    > Any assistance at this point would be greatly appreciated.
    >
    > Thanks !
    > Steve
    >
    > Here's a simple example that works in IE but returns null for
    > responseText in Mozilla when I run it ...
    >
    > <HTML>
    > <HEAD>
    > <SCRIPT LANGUAGE="JAVAS CRIPT" type="text/javascript">
    > <!--
    > var xmlhttp=false;
    > /*@cc_on @*/
    > /*@if (@_jscript_vers ion >= 5)
    > // JScript gives us Conditional compilation, we can cope with old IE
    > versions.
    > // and security blocked creation of the objects.
    > try {
    > xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
    > } catch (e) {
    > try {
    > xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
    > } catch (E) {
    > xmlhttp = false;
    > }
    > }
    > @end @*/
    > if (!xmlhttp && typeof XMLHttpRequest! ='undefined') {
    > xmlhttp = new XMLHttpRequest( );
    > }
    >
    > function RSchange() {
    > if (xmlhttp.readyS tate==4) {
    > //if (xmlhttp.status == 200) {
    > //alert(xmlhttp.s tatusText); // this line chokes in Mozilla
    > alert(xmlhttp.r esponseText); //empty alert box using Moz
    > // }
    > }
    > }
    >
    > function go() {
    > if (xmlhttp) {
    > xmlhttp.open("G ET", "http://myserver.com/index.html", true);[/color]

    Is http://myserver.com/index.html on the same server as the HTML
    document with the script? What content type does the server deliver
    index.html with?


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • fochie

      #3
      Re: xmlhttp problem using Mozilla ... responseText is always null

      Line 26 is the following -
      if (xmlhttp.status == 200) { (sorry, I also put the comment on the
      wrong line in the snippit above)

      Not using frames.

      The page I'm trying to retrieve is on the same server (same dir also)
      as the html containing the xmlhttp call.

      Not sure what content type is being used by the server for delivering
      index.html. Is this an Ap[ache directive ?
      Maybe I should issue an xmlhttp HEAD call using IE (since Moz fails
      with the same error msg mentioned above if I try to do a HEAD request)
      and see what Content type is being returned ?

      Thanks for the reply !
      Steve

      Comment

      • Martin Honnen

        #4
        Re: xmlhttp problem using Mozilla ... responseText is always null



        fochie wrote:
        [color=blue]
        > Line 26 is the following -
        > if (xmlhttp.status == 200) { (sorry, I also put the comment on the
        > wrong line in the snippit above)
        >
        > Not using frames.
        >
        > The page I'm trying to retrieve is on the same server (same dir also)
        > as the html containing the xmlhttp call.
        >
        > Not sure what content type is being used by the server for delivering
        > index.html. Is this an Ap[ache directive ?
        > Maybe I should issue an xmlhttp HEAD call using IE (since Moz fails
        > with the same error msg mentioned above if I try to do a HEAD request)
        > and see what Content type is being returned ?[/color]

        If that is an HTML page you can simply load it in a Mozilla window and
        then check page info for details on the content type Mozilla receives.

        --

        Martin Honnen
        http://JavaScript.FAQTs.com/

        Comment

        • fochie

          #5
          Re: xmlhttp problem using Mozilla ... responseText is always null

          When I issue the following HEAD equest in IE it returns -
          Content-Type: text/html
          If I issue the same request in Moz it throws this in the javascript
          console-

          Error: [Exception... "Component returned failure code: 0x80040111
          (NS_ERROR_NOT_A VAILABLE) [nsIXMLHttpReque st.getAllRespon seHeaders]"
          nsresult: "0x80040111 (NS_ERROR_NOT_A VAILABLE)" location: "JS frame ::
          http://timegonebuy.com/javascript_XML.html? :: anonymous :: line 123"
          data: no]
          Source File: http://timegonebuy.com/test_javascript_XML.html?
          Line: 123

          This is Line 123 -

          alert('header returned is ' +xmlhttp.getAll ResponseHeaders ())

          Here's what was issues -

          try {

          xmlhttp.open("H EAD", "http://myserver.com/index.html",tru e);
          xmlhttp.onready statechange=fun ction() {
          if (xmlhttp.readyS tate==4) {
          alert('header returned is ' +xmlhttp.getAll ResponseHeaders ())
          }
          }
          xmlhttp.send(nu ll)
          }
          catch (e) { alert('failed') ; }

          Comment

          • fochie

            #6
            Re: xmlhttp problem using Mozilla ... responseText is always null

            bring up the html in Mozilla and using Page Info shows type - text/html

            Comment

            • VK

              #7
              Re: xmlhttp problem using Mozilla ... responseText is always null

              How do you start your script? Is it a form button click? Of what type?

              Comment

              • fochie

                #8
                Re: xmlhttp problem using Mozilla ... responseText is always null

                from the snippit above ... this is how the function gets invoked ...
                maybe I have this twisted up
                since it's type=submit and also has an onclick ? -
                ..
                ..
                ..
                </head>
                <BODY>
                <FORM NAME='' ACTION='' onsubmit="retur n true;">
                <INPUT TYPE="SUBMIT" VALUE='getit' onclick="go()"
                </FORM>
                </BODY>
                </HTML>


                Thanks for the reply ... hope someone can help me get past this soon
                .... been bangin my head against it for over a week

                Comment

                • fochie

                  #9
                  Re: xmlhttp problem using Mozilla ... responseText is always null

                  THAT WAS THE PROBLEM ! .... I changed it to "type=butto n" and now the
                  file is received/displayed in Mozilla ... thanks for the pointer !!!!!
                  ... obviously I need to pay more attention to the basic HTML pieces as
                  well ... IE must be forgiving in this scenario .... thanks again !!!!

                  Comment

                  • VK

                    #10
                    Re: xmlhttp problem using Mozilla ... responseText is always null

                    Glad it helped.
                    Just to make sure you got the problem right (to not repeat it):

                    ...
                    form.submit();
                    some code after
                    ....

                    or

                    ....
                    document.locati on.hred = someURL;
                    some code after
                    ....

                    are equally wrong, because the first statement clears the current DOM /
                    script data. It's like trying to continue the conversation with a
                    person after you shoot him in the temple. Some "post mortum" may occur
                    (script is still working) because a part of code was retained in the
                    program cache (orphaned script). But you cannot make any reliable
                    accumptions about it.

                    Comment

                    Working...