Strange AJAX Issue?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    Strange AJAX Issue?

    I'm having an issue with my AJAX function, its been working fine then I added another link, and now when i click on an AJAX link on the menu, it tries to load the correct page for a split second and then goes back to the menu page, just can't figure it out!?!It works fine on my local setup but once i moved the new link to the live site its stopped working!???
    Code:
    <script type="text/javascript" language="javascript">
    	var loading_img = '/media/images/layout/loading.gif';
    	var loading_msg = ' Loading...';
    	var xmlhttp_obj = false;//create the XMLHttpRequest
    	
    	function ewd_xmlhttp()
    	{
    		if (window.XMLHttpRequest)
    		{ // if Mozilla, Safari etc
    			xmlhttp_obj = new XMLHttpRequest();
    		}
    		else if (window.ActiveXObject)
    		{ // if IE
    			try
    			{
    				xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP");
    			}
    			catch (e)
    			{
    				try
    				{
    					xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP");
    				}
    				catch (e)
    				{
    
    				}
    			}
    		}
    		else
    		{
    			xmlhttp_obj = false;
    		}
    
    		return xmlhttp_obj;
    	}   //get content via GET
    
    	function getcontent(url, containerid)
    	{
    		var xmlhttp_obj = ewd_xmlhttp();
    		document.getElementById(containerid).innerHTML = '<img src="' + loading_img + '" />' + loading_msg;
    		xmlhttp_obj.onreadystatechange=function()
    		{
    			loadpage(xmlhttp_obj, containerid);
    		}
    		xmlhttp_obj.open('GET', url, true);
    		xmlhttp_obj.send(null);
    	}     
    
    	function loadpage(xmlhttp_obj, containerid)
    	{
    		if ( xmlhttp_obj.readyState == 4 && xmlhttp_obj.status == 200 )
    		{
    			document.getElementById(containerid).innerHTML = xmlhttp_obj.responseText;
    		}
    	}
    //]]>
    </script>
  • ziycon
    Contributor
    • Sep 2008
    • 384

    #2
    I've done some investigation into this issue and I've found that the correct page is loaded after the first alert but when i clear the second alert from the screen it goes back to the menu page??
    Code:
    function getcontent(url, containerid)
         {
             var xmlhttp_obj = ewd_xmlhttp();
             document.getElementById(containerid).innerHTML = '<img src="' + loading_img + '" />' + loading_msg;
             xmlhttp_obj.onreadystatechange=function()
             {
                 loadpage(xmlhttp_obj, containerid);
             }
             alert(url);
             xmlhttp_obj.open('GET', url, true);
             xmlhttp_obj.send(null);
             alert(url);
         }

    Comment

    • ziycon
      Contributor
      • Sep 2008
      • 384

      #3
      Fixed it, i hadn't got the 'return false;' at the end of the link.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        glad to hear you got it working and posting the solution here so that other members could find it and the hint where to look into when they encounter similar problems.

        thanks and kind regards

        Comment

        Working...