Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts

    Internet Explorer Object not found in Internet Explorer

    When I run the following code in FF it works fine, but when I run in IE the process completes but the end image doesn't update, when I debug I get an object not found error (although, clearly the object is there or else FF would not work either!).

    Code:
    function ajaxFunction($todo,$status)
    {
    var xmlHttp;
    try
      {// Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {// Internet Explorer
      try
        {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
      catch (e)
        {
        try
          {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
        catch (e)
          {alert("Your browser does not support AJAX!");return false; }
        }
      }
      xmlHttp.onreadystatechange=function()
        {
        if(xmlHttp.readyState==4)
          {
    	  if("mood" == $todo){document.MoodImg.src="style/"+xmlHttp.responseText+".png";}
    	 
          }
        }
    	 if("mood" == $todo){xmlHttp.open("GET","change.php?type=mood",true);}
    
       xmlHttp.setRequestHeader("If-Modified-Since", "Fri, 31 Dec 1999 23:59:59 GMT");
      xmlHttp.send(null);
      }
    And the object is found...

    Code:
    <div id="MoodIcon">
    				<img id="MoodImg" src="style/<?PHP echo $mood; ?>.png" /><a onclick="ajaxFunction('mood','');">Change Mood</a>
    			</div>
    The change.php file does its job correctly and contains no JS.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    The correct way to reference an object with an id is:

    document.getElementById("elementID")

    I am sure FF is giving you a warning about bad syntax.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • Users who have thanked A1ien51 for this post:

    tosbourn (10-09-2008)

  • #3
    Regular Coder
    Join Date
    Aug 2008
    Location
    Northern Ireland
    Posts
    167
    Thanks
    12
    Thanked 6 Times in 6 Posts
    Gah! You are right (although I must have error reporting turned off on FF)

    Thanks!


  •  

    Tags for this Thread

    Posting Permissions

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