IE incompatibilities with AJAX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tromboneman
    New Member
    • Aug 2007
    • 7

    #1

    IE incompatibilities with AJAX

    Hi!

    I haven't been coding in Javascript/PHP very long, but this is the first thing some time and Google can't solve. Through my hours of debugging, I have narrowed the problem down to (unsurprisingly ) Internet Explorer. I have a HttpXML request being sent to the the file manager.php. Here is the contents of manager.php:

    Code:
    <?php
    /*This page manages the typing/not-typing ajax light in area.php*/
    $sender=$_GET["sender"];
    
    //Mode 1: Makes sure the file is set to "typing" (1), and then returns 1
    if($sender==1)
    {
    	$file=fopen('typing.txt', "w");
    	fwrite($file, 1);
    	fclose($file);
    	echo 1;
    }
    
    //Mode 2: Makes sure the file is set to "not typing" (2), and then returns 2
    else if($sender==2)
    {
    	$file=fopen('typing.txt', "w");
    	fwrite($file, 2);
    	fclose($file);
    	echo 2;
    }
    
    //Mode 3: Returns typing or not typing (1 or 2)
    else if($sender==0)
    {
    	$file=fopen('typing.txt', "r");
    	$value=fgetc($file);
    	fclose($file);
    	echo $value;
    }
    else
    {
    	die("Error!  Please contact your server admin!");
    }
    ?>
    The url is either manager.php?sen der=0, manager.php?sen der=1, or manager.php?sen der=2. What seems to happen is that IE cannot write or read from the file. 2 simultaneous Firefox clients can read data written by the other, but IE can't read data from others, or write data itself. It DOES, however, still return the value 1 or 2 if sender = 1 or 2 respectively. This is what I don't understand. It obviously does execute that code block since it can return 1 or 2, and it works great on Firefox and Opera. My server is running Linux with Apache 2. I have been trying to figure out what is wrong with this for days. Any help would be appreciated.

    Thank you!

    P.S.-It has never died with that error
  • tromboneman
    New Member
    • Aug 2007
    • 7

    #2
    Does anyone have any ideas? I still haven't been able to figure out what is wrong. Should have I posted this in the PHP forum?

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Post the code you are using for the request.

      Comment

      • tromboneman
        New Member
        • Aug 2007
        • 7

        #4
        Thank you for your reply. This is the javascript that is making the request.

        Code:
        function checktype(sender)
          {
        
          
          //Make the AJAX object
          if(xmlHttp==null)
          {
          //alert("new object");
          try
            {
            // Good, you are using a great browser
            xmlHttp=new XMLHttpRequest();
            }
          catch (e)
            {
            // Do yourself a favor: go to mozilla.org and download Firefox, or even better, just switch to Linux
            try
              {
        	  //Boo!
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
              }
            catch (e)
              {
              try
                {
        		//Obsolete Boo!
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
              catch (e)
                {
        		//Don't worry!  I still love you, Elinks!  You are just a little bit...   uh...   old?
                alert("Your browser does not support this Hablator feature.  Contact the Administrator!");
                return false;
                }
              }
            }
           }
         /*     else
           {
        	  xmlHttp.abort();
           }*/
        
        
        	url='manager.php?sender='+sender.toString();
        	
        	xmlHttp.open("GET", url, true);
        	 
        	xmlHttp.onreadystatechange=function()
        	{
        	 if(xmlHttp.readyState==4)
        	 {
        	  temp = xmlHttp.responseText;
        	  //alert(temp);
        	  form1.temp8.value=temp;
        	  if(temp==1|temp=="1")
        	   document.images['typing'].src="img/on.gif";
        	  if(temp==2|temp=="2")
        	   document.images['typing'].src="img/off.gif";
        	 }
        	}
        
        
        	 xmlHttp.send(null);
        	
          }

        Also, the Firefox error console reports the following error:

        Code:
        Error: uncaught exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: http://bernsteinforpresident.com/mytalk/0.2/light.js :: checktype :: line 80"  data: no]
        Thanks!

        Comment

        • tromboneman
          New Member
          • Aug 2007
          • 7

          #5
          Okay, I just figured out the problem. It was one, simple line in my PHP file.

          [PHP]header("Cache-Control: no-cache");[/PHP]

          Thanks!

          Comment

          Working...