www.webdeveloper.com
Results 1 to 2 of 2

Thread: Page loads nothing for forever in firefox (IE?)

  1. #1
    Join Date
    Nov 2007
    Posts
    11

    Page loads nothing for forever in firefox (IE?)

    Hello all,
    I'm having some trouble with my AJAX library. My page starts the way it should, by retrieving the text "Hello world!" from info.txt and puts it in the body. Problem is, after that, Firefox tries to load something. I don't even know what. The request doesn't show up in firebug. And many other weird things happen, such as, when looking at the page source, all I see is the text it loaded, and I can't create a new line in this text box unless I press Shift+Enter (this only happens some times).
    Anyway here's my scripts. Many thanks for any errors you can weed out...
    ajaxlibrary.js:
    Code:
    function AjaxLibrary() {
      this.AjaxHandle = function() {  //CALL THIS FIRST!!! Returns Handle for an XMLHttpRequest or -1 for a browser that doesn't support AJAX
        if(typeof ActiveXObject != "undefined") {
          try {
            XMLHRH = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (XHRH_Except1) {
            try {
              XMLHRH = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (XHRH_Except2) {
              return -1;
            }
          }
        } else if (XMLHttpRequest) {
          try {
            XMLHRH = new XMLHttpRequest();
          } catch (XHRH_Except3) {
            return -1;
          }
        }
    	return XMLHRH;
      };
      
      this.LoadPage = function(RequestHandle, RequestURL, CallBack, State1, State2) { //Call to load a page. RequestHandle should be return value from AjaxHandle,
        // CallBack should be function called when readyState changes (as well as when page has been loaded; it needs 2 args: 1 is readystate, 2 is responsetext), and
    	// State1 & State2 are optional, readystatechange function is called if readyState is equal to one of these. Callback should also take -1 for error loading page.
        RequestHandle.onreadystatechange = function() {
    	  if (RequestHandle.readyState == State1) {
            CallBack(State1);
    	  } else if (RequestHandle.readyState == State2) {
            CallBack(State2);
    	  } else if (RequestHandle.readyState == 4) {
    	    if (RequestHandle.status==200) {
    		  CallBack(4, RequestHandle.responseText);
    		  RequestHandle.abort();
    		} else {
    		  CallBack(-1);
    		  RequestHandle.abort();
    		}
    	  }
        };
        preventCache = (RequestURL.indexOf("?")!=-1) ? "&" + new Date().getTime() : "?" + new Date().getTime();
        RequestHandle.open('GET', RequestURL + preventCache, true);
        RequestHandle.send(null);
      };
    }
    testajaxlibrary.html:
    HTML Code:
    <html>
      <head>
        <title>Test AjaxLibrary.js</title>
    	<script type="text/javascript" src="./ajaxlibrary.js"></script>
      </head>
      <body>
        <script type="text/javascript">
    	  var HandleLoading = function(RequestStatus, ResponseText) {
    	    if (RequestStatus == 4) {
    	      document.write(ResponseText);
    	    }
    	  }
    	
    	  AjaxLib = new AjaxLibrary;
    	  AjaxHandle = AjaxLib.AjaxHandle();
    	  AjaxLib.LoadPage(AjaxHandle, "./info.txt", HandleLoading);
    	</script>
      </body>
    </html>
    Many thanks for any help!

    P.S. - In IE, this page loads fine at first, but when I try to get it to load again (not via refresh), it will also load nothing for forever. and clicking the X won't make it stop. Trying to close the window, it says that the window is busy and closing it might cause some problems.
    This is becoming very confusing...

  2. #2
    Join Date
    Feb 2006
    Posts
    2,926
    document.write(ResponseText);
    This replaces the original page with the text response.

    Until you call document.close() in the new document,
    from a script you include in the document.write,
    it will keep waiting for more input.
    Last edited by mrhoo; 10-04-2008 at 10:10 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles