[web] this is retarded

Started by
2 comments, last by ID Merlin 15 years, 8 months ago

<script type="text/&#106avascript" language="&#106avascript"&gt;
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 &#111;n failure)
	if( !getit ) 
	{
		alert( "AJAX Object not defined!" );
	}
	
    if( getit.readyState == 4 || getit.readyState == 0)
    {
	    getit.open("GET", 'delme.htm', true);
		getit.send(null);
	}
}


&lt;/script&gt;
&lt;span &#115;tyle="cursor: pointer; text-decoration: underline" &#111;nclick="LoadNode()"&gt;open self&lt;/span&gt;
&lt;div id='ajaxcontent' type='text' size='20' name='ajaxcontent'&gt;..End of Page</div>
</pre>

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 &#111;ne time &#111;nly?) whereas in FFox, the behavior is repeatable?
"a low level aho master like you couldn't kill me even if I let you"
Advertisement
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

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

worked perfectly

thanks =D
"a low level aho master like you couldn't kill me even if I let you"
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.

This topic is closed to new replies.

Advertisement