Sign in to follow this  
Uthman

[web] this is retarded

Recommended Posts

<script type="text/javascript" language="javascript">
function AJAXObj( callback_function )
{
	var http_request = false;
	if( window.XMLHttpRequest )
	{
		http_request = new XMLHttpRequest();	// Mozilla, Safari,...
		if( http_request.overrideMimeType ) http_request.overrideMimeType('text/xml');
	
	} else if( window.ActiveXObject )
	{	// IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if( !http_request )
	{
		alert('Browser doesn\'t support Ajax');
		return false;
	}

	http_request.onreadystatechange = function()
	{
		if( http_request.readyState == 4 )
		{
			if( http_request.status == 200 )
			{
				eval(callback_function + '(http_request.responseText)');	// eval(callback_function + '(http_request.responseXML)');
			} else
				alert('There was a problem with the request.(Code: ' + http_request.status + ')');
		}
	}

	return http_request;
}
   
function loadHTML(html_data)
{
	var ele = document.getElementById('ajaxcontent').innerHTML = html_data;

}

////////////////////////////////////////
////////////////////////////////////////

var getit = AJAXObj( 'loadHTML' );

function LoadNode( )
{	// If we wanna get fancy, we can display a loading image here (with a return-1 history on failure)
	if( !getit ) 
	{
		alert( "AJAX Object not defined!" );
	}
	
    if( getit.readyState == 4 || getit.readyState == 0)
    {
	    getit.open("GET", 'delme.htm', true);
		getit.send(null);
	}
}


</script>
<span style="cursor: pointer; text-decoration: underline" onclick="LoadNode()">open self</span>
<div id='ajaxcontent' type='text' size='20' name='ajaxcontent'>..End of Page
save this page to a file called 'delme.htm' and test it in IE vs firefox. why is the behavior in IE so strange (works one time only?) whereas in FFox, the behavior is repeatable?

Share this post


Link to post
Share on other sites
Quote:
Original post by Sander
You can't easily reuse the AJAX object in IE. See:
http://en.wikipedia.org/wiki/XMLHttpRequest#Reusing_XMLHttpRequest_Object_in_IE
http://keelypavan.blogspot.com/2006/03/reusing-xmlhttprequest-object-in-ie.html


I knew someone would have the answer. I found that once, and modified my code, but I took out the comments so if someone stole it, they'd be clueless. I probably should have left that comment in there.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this