Forum Moderators: open

Message Too Old, No Replies

Get http problem

         

andrewds

9:23 pm on Dec 19, 2006 (gmt 0)

10+ Year Member



Hey I have the following code:


<script>
var http;
function getPage(url)
{
if ((navigator.appName.indexOf("Microsoft")>-1) ¦¦ (navigator.appName.indexOf("MSIE")>-1))
{
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
http = new XMLHttpRequest();
}
if (http)
{
http.open("get", "sources/mainNav/" + url + ".php");
http.onreadystatechange = handleResponse;
http.send(null);
}
}
function handleResponse()
{
if (http.readyState == 4)
{
var content = http.responseText;
if (content && content!= "")
document.getElementById("innerContent").innerHTML = content;
}
}
</script>

Then to call it:

<a href="#" onclick="getPage('allproducts');">All Products</a> 

And it should change:

<p id="innerContent"></p>

This works perfectly fine in Firefox 2, but I have tested this script on 3 machines with IE7, and 2 with IE6, and it doesn't change the paragraph inner content.

So just wondering if you know the problem.

Thanks
Andy

DrDoc

5:29 pm on Dec 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps I may suggest a different approach to the "browser sniffing."

<script type="text/javascript"> 
var http= false;
function getPage(url)
{
if(window.XMLHttpRequest)
{
// Mozilla, Safari, ...
http = new XMLHttpRequest();
if(http.overrideMimeType)
{
http.overrideMimeType('text/xml');
}
}
else if(window.ActiveXObject)
{
// IE
try
{
http = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
http = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}

if (http)
{
http.open("get", "sources/mainNav/" + url + ".php");
http.onreadystatechange = handleResponse;
http.send(null);
}
}
function handleResponse()
{
if (http.readyState == 4)
{
var content = http.responseText;
if (content && content!= "")
document.getElementById("innerContent").innerHTML = content;
}
}
</script>

andrewds

5:34 pm on Dec 21, 2006 (gmt 0)

10+ Year Member



Thanks for this, however it doesn't work, I think to problem is the program I am using

JQuery and ThickBox, and that IE doesnt support extra javascript/ajax within the box.
But FireFox does, what I shall do is contact the creator of ThickBox to see if he knows of this, and a possible fix to my problem.

Thanks anyway
Andy