xmlrequest status codes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dols
    New Member
    • Mar 2007
    • 2

    #1

    xmlrequest status codes

    Hello,

    below the fragment that works fine, but nevertheless, the value of xmlhttp.status
    turns out to be zero (0), and the corresponding value for xmlhttp.statusT ext is "unknown".

    Does anyone know the details of ALL the statuscodes when the value for readyState is 4 (= completed).


    Also, where could I have found the answer myself???

    thanks,

    Frens


    xmlhttp.open("G ET", "test.txt",true );
    xmlhttp.onready statechange=fun ction() {

    if (xmlhttp.readyS tate==4) {
    window.alert("S how the stuff");}
    }
    xmlhttp.send(nu ll)

    window.alert(xm lhttp.readyStat e);
    window.alert(xm lhttp.responset ext);
    window.alert(xm lhttp.responseX ML);
    window.alert(xm lhttp.status);
    window.alert(xm lhttp.statusTex t);
  • dols
    New Member
    • Mar 2007
    • 2

    #2
    Status codes after GET and SEND

    Hello,

    anyone know why status code after the GET and SEND is 0?

    It should be 200 since the file has been loaded and can be assessed.

    thanks,

    Frens



    <script type="text/javascript">


    var xmlhttp;

    xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");

    if (xmlhttp) {
    document.write( '<p class="example" ><a href="#" onclick="exampl e();return false;">Try the example.</a></p>')
    }

    function example() {

    xmlhttp.open("G ET","just some text.txt",true) ;
    xmlhttp.onready statechange=fun ction() {


    if (xmlhttp.readyS tate == 4)
    if (xmlhttp.status == 200)
    alert("Server is done!");
    else if (xmlhttp.status == 404)
    alert("Request URL does not exist");
    else
    alert("Error: status code is " + xmlhttp.status) ;

    if (xmlhttp.readyS tate==4) {
    if (xmlhttp.status ==0) { // !! This should be 200 since all seems right

    var local=new Function("retur n "+xmlhttp.respo nseText)();
    window.alert(xm lhttp.responseT ext);

    window.alert("C ode - Name\n"+local[0].id+' - '+local[0].name);

    } else {
    alert("not found");
    }

    } // end statechangefunc tion

    } // end example function

    xmlhttp.send(nu ll);

    }
    </script>

    Comment

    • quill
      New Member
      • Mar 2007
      • 12

      #3
      Hi,

      Your ajax code seems to rely on IE (activeX). Try looking at

      http://www-128.ibm.com/developerworks/web/library/wa-ajaxintro1.html

      And use the cross-browser Ajax code.

      Comment

      • quill
        New Member
        • Mar 2007
        • 12

        #4
        Originally posted by dols
        xmlhttp.open("G ET", "test.txt",true );
        xmlhttp.onready statechange=fun ction() {

        if (xmlhttp.readyS tate==4) {
        window.alert("S how the stuff");}
        }
        xmlhttp.send(nu ll)

        window.alert(xm lhttp.readyStat e);
        window.alert(xm lhttp.responset ext);
        window.alert(xm lhttp.responseX ML);
        window.alert(xm lhttp.status);
        window.alert(xm lhttp.statusTex t);
        Here's a link:



        Check out table 2.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Merged threads.

          Comment

          Working...