SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot backtobasics's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need some advice on this Ajax script

    OK, so I am using the following Ajax script:

    Code:
    function switch_cat(cat)
    {
    	var xmlhttp=false;
    	
    	try
    	{
    		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); 
    	}
    	
    	catch(e)
    	{
    		try
    		{
    			xmlhttp = new
    			ActiveXObject('Microsoft.XMLHTTP'); 
    		}
    		
    		catch(E)
    		{
    			xmlhttp = false;
    		}
    	}
    	
    	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
    	{
    		xmlhttp = new XMLHttpRequest();
    	}
    	
    	var file = 'cats.php?cat='; 
    	xmlhttp.open('GET', file + cat, true);
    	//document.getElementById('content').innerHTML = "Loading..."; 
    	
    	xmlhttp.onreadystatechange = function()
    	{
    		if (xmlhttp.readyState >0 && xmlhttp.readyState <4)
    		{ 
    			document.getElementById('content').innerHTML = "";
    		}
    		
    		else if (xmlhttp.readyState == 4)
    		{ 
    			var content = xmlhttp.responseText; 
    			if (content)
    			{ 
    				document.getElementById('content').innerHTML = content; 
    			}
    		}
    	}
    	
    	xmlhttp.send(null);
    	return;
    }
    As you can see, what is happening is that it loading data from an external PHP script, for example, cats.php?cat=1.

    I'm noticed some problems with this in IE 6, where instead of putting only the raw text generated from the external file, it puts in ALL the content from the main page which is calling this script.

    Is there any better way for me to go about this? Or any changes I could make to this script?

    Thanks in advance.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm noticed some problems with this in IE 6,
    Your "script" doesn't do anything in any browser; it's just a function definition. Post a simple example that demonstrates your problem. Include a php page that is no more than 3 lines of code, some simple html--like one button, and state the expected results and the actual results.

  3. #3
    SitePoint Zealot backtobasics's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 7stud View Post
    Your "script" doesn't do anything in any browser; it's just a function definition.
    I never said it did. I said I'm having problems in IE6, that doesn't mean that I'm running the script directly in a browser.

    Nevermind. Thanks anyways..

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should display the same content in the div that you get when navigating directly to cats.php?cat=something


Bookmarks

Posting Permissions

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