Jump to content

XMLHttpRequestObject.status returns 0


orion-

Recommended Posts

When this code is ran the XMLHttpRequestObject.status returns 0. Preventing the code inside the if to be ran. What could be the cause of this?

thanks in advance

[code]var offsetX, offsetY;
 
      function MouseEvent(e)
      {
        if(e) {
          this.e = e;
        } else {
          this.e = window.event;
        }

        if(e.pageX) {
          this.x = e.pageX;
        } else {
          this.x = e.clientX;
        }

        if(e.pageY) {
          this.y = e.pageY;
        } else {
          this.y = e.clientY;
        }

        if(e.target) {
          this.target = e.target;
        } else {
          this.target = e.srcElement;
        }
      }
 
      function addListener(type, callback)
      {
        if (document.addEventListener) {
          document.addEventListener(type, callback, false);
        } else if (document.attachEvent) {
          document.attachEvent("on"+type, callback, false);
        }
      }
 
      function removeListener (type, callback)
      {
        if (document.removeEventListener) {
          document.removeEventListener(type, callback, false);
        } else if (document.detachEvent) {
          document.detachEvent("on" + type, callback, false);
        }
      }
 
      function handleDown(e)
      {
        var e = new MouseEvent(e);
        addListener("mousemove", handleMove);
        addListener("mouseup", handleUp);
        offsetX = e.x - parseInt(e.target.style.left);
        offsetY = e.y - parseInt(e.target.style.top);
        document.getElementById("targetDiv").innerHTML = "";
      }
   
      function handleMove(e)
      {

        var e = new MouseEvent(e);
        var x = e.x - offsetX;
        e.target.style.left = x + "px";
        var y = e.y - offsetY;
        e.target.style.top = y + "px";
      }
   
      function handleUp(e)
      {
 
        var e = new MouseEvent(e);
        removeListener("mousemove", handleMove);
        removeListener("mouseup", handleUp);

        var target = document.getElementById("target");
        var x = parseInt(target.style.left);
        var y = parseInt(target.style.top);
        var width = parseInt(target.style.width);
        var height = parseInt(target.style.height);

        if(e.x > x && e.x < x + width &&
          e.y > y && e.y < y + height){
          var XMLHttpRequestObject = false;

          if (window.XMLHttpRequest) {
            XMLHttpRequestObject = new XMLHttpRequest();
          } else if (window.ActiveXObject) {
            XMLHttpRequestObject = new
            ActiveXObject("Microsoft.XMLHTTP");

          }

          if(XMLHttpRequestObject) {
 
            XMLHttpRequestObject.open("GET", "text.txt");

            XMLHttpRequestObject.onreadystatechange = function()
            {
              [b]if (XMLHttpRequestObject.status == 200 && XMLHttpRequestObject.readyState == 4)[/b]
                )
{

                  document.getElementById("targetDiv").innerHTML =
                    XMLHttpRequestObject.responseText;
                  delete XMLHttpRequestObject;
                  XMLHttpRequestObject = null;
              }
            }

            XMLHttpRequestObject.send(null);
          }
        }
      }[/code]
Link to comment
Share on other sites

This code came from a book "Ajax for Dummies" and I am just trying to understand why I does'nt work.

Where would you suggest I would do the send? I can't place it in XMLHttpRequestObject.onreadystatechange = function() because then it would do a send every time the readystate changes, right?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.