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 8 of 8

Thread: Newbie AJAX

  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    54
    Thanks
    2
    Thanked 1 Time in 1 Post

    Newbie AJAX

    Hello Peeps.

    Sorry if this is basic stuff but I am waiting for my Book to arive and tring to do a little bit before it arrives.

    I have a simple script to collect some php data (Just some Text) and display in div on mouseover.

    All works fine apart from if I update the data (In other words add more text). The update happens correctly in Firefox but Not in IE.

    Here is the simple script.

    Hopefully some one can give me some pinters.

    Code:
    <script type="text/javascript">
          var XMLHttpRequestObject = false; 
    
          if (window.XMLHttpRequest) {
            XMLHttpRequestObject = new XMLHttpRequest();
          } else if (window.ActiveXObject) {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
          }
    
          function getData(dataSource, divID) 
          { 
            if(XMLHttpRequestObject) {
              var obj = document.getElementById(divID); 
              XMLHttpRequestObject.open("GET", dataSource); 
    
              XMLHttpRequestObject.onreadystatechange = function() 
              { 
                if (XMLHttpRequestObject.readyState == 4 && 
                  XMLHttpRequestObject.status == 200) { 
                    obj.innerHTML = XMLHttpRequestObject.responseText; 
                } 
              } 
    
              XMLHttpRequestObject.send(null); 
            }
          }
        </script>
    
    And the HTML.
    
    <a href="#" onmouseover="getData('/includes/data.php?event=showuser', 'targetDiv')">Show Users</a> | <a href="#" onmouseover="getData('/includes/data.php?event=showblog', 'targetDiv')">Show Latest Blog</a>	
    		
        <div id="targetDiv"></div>
    I guess this has something to do with the DOM and ie.

    Hope you can shed some light.

    Regards & Thanks

  • #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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    54
    Thanks
    2
    Thanked 1 Time in 1 Post
    Hello Again Eric

    That didnt work.

    Regards

    Lee

  • #4
    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
    You ever look at my answer?
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    I'm not sure if this will solve your problem or not, and I didn't really read through Eric's replies, but you may try just appending the current date / time to your url or post string. I had the problem you describe before and it seems to have rectified it.

    Example:

    Code:
    function getReqObj(url,func)
    {
    	if (window.XMLHttpRequest)
      	{
     		xmlhttp=new XMLHttpRequest();
     	}
     	else if (window.ActiveXObject)
        {
        	if(new ActiveXObject("Microsoft.XMLHTTP"))
        	{
        		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        	}
        	else
        	{
        		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
        	}
        }
      	xmlhttp.onreadystatechange=function()
      	{
      		if(xmlhttp.readyState==4)
    		{						
    			if(xmlhttp.status==200)
    			{
    				if(document.getElementById('nextPage'))
    				{
    					document.getElementById('nextPage').style.display='inline';
    				}
    				var last_mod=xmlhttp.getResponseHeader("Last-Modified");
    				var req=xmlhttp.responseXML;
    				var req_str=xmlhttp.responseText;
    				eval(func);
    			}
    			else
    			{
    				noData(xmlhttp.status);	
    			}
    		}
      	}
    	var now=new Date();
    	
    	if(url.indexOf("?")==-1)
    	{
    		var cut=url.substring(0,url.length);
    		var s=cut+"?c_date="+now;
    	}
    	else
    	{
    		var cut=url.split('?');
    		var s=cut[0]+"?c_date="+now+"&"+cut[1];
    	}
    	xmlhttp.open("GET",url,true);
    	xmlhttp.send(null);
    }
    Basscyst
    Last edited by Basscyst; 04-11-2006 at 05:50 PM.
    Helping to build a bigger box. - Adam Matthews

  • #6
    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
    Basscyst,

    You need to have try catch around the ActiveX portion. If ActiveX is disabled you get an error message.

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

  • #7
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #8
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by A1ien51
    Basscyst,

    You need to have try catch around the ActiveX portion. If ActiveX is disabled you get an error message.

    Eric
    Okay. I'll add that in, thanks.

    Basscyst
    Helping to build a bigger box. - Adam Matthews


  •  

    Posting Permissions

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