469,592 Members | 2,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

"Object Required" by IE 6 when using Msxml2.XMLHTTP

This AJAX stuff is all new to me. To try it out, I borrowed this code
from a website:

========================

var http_request = false;
function makeRequest(url) {

http_request = false;

if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');

}
}
else if (window.ActiveXObject)
{ // IE
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
//Failure on above line!
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
}
}
}
=======================

In Firefox and Safari, I'm having great success. In IE 6, I get an
"Object Required" failure while trying to run this line:

http_request = new ActiveXObject("Msxml2.XMLHTTP");

I guess I'm missing something pretty basic. Can someone point me in the
right direction?
Thanks!

--Brent
Nov 23 '05 #1
5 3544
You will hate it, but I cut & paste your code and it works without
error in IE6... this is what I copied from Google:

function connect() {
var C=null;
try {
C=new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e) {
try{
C=new ActiveXObject("Microsoft.XMLHTTP")
}
catch(sc) {
C=null
}
}
if(!C && typeof XMLHttpRequest!="undefined") {
C=new XMLHttpRequest()
}
return C;
}

but it looks like your code :( I don't see anything wrong in your code
except that you set http_request to false twice (i would set it to
"null" to start with), and you don't return it. Try my code see if it
works!

Nov 23 '05 #2
Yes, your code works fine. With the addition of the open() and send()
methods (and a closing brace for your function), I get a positive
response. Could you post the rest of your code?

Nov 23 '05 #3
Thanks for your replies! The entire code <script> to </script> is
attached. I haven't made any changes overnight...and it's still not
working! ;=)

================================================== =================

<script type="text/javascript" language="javascript">

var http_request = null;

function makeRequest(url) {

if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
// See note below about this line
}
}
else if (window.ActiveXObject)
{ // IE
try
{
if (!http_request)
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
}
}
}

if (!http_request)
{
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);

}

function alertContents() {

if (http_request.readyState == 4) {
if (http_request.status == 200) {

var xmldoc = http_request.responseXML;
var divid_node = xmldoc.getElementsByTagName('divid').item(0);
var id = document.getElementById(divid_node.firstChild.data );

var data_node = xmldoc.getElementsByTagName("data");
var outText = "";

for (i=0;i<data_node.length;i++)
{
var thisitem = data_node[i];
var sid =
thisitem.getElementsByTagName("gics_code").item(0) .firstChild.data;
var thiscount =
thisitem.getElementsByTagName("count").item(0).fir stChild.data;

outText += '<div><a href="sector.aspx?sid='+ sid +'">' +
thisitem.getElementsByTagName("gicdesc").item(0).f irstChild.data + '
('+thiscount+')</a></div>';
}
id.innerHTML = outText;
} else {
alert('There was a problem with the request.');
}
}

}

function ShowHide(divId)
{
var id = document.getElementById(divId);
id.style.display = ('none' == id.style.display)? '':'none';
}

</script>
Nov 23 '05 #4
Brent <"writeBrent at the google mail place"> wrote:

In Firefox and Safari, I'm having great success. In IE 6, I get an
"Object Required" failure while trying to run this line:

http_request = new ActiveXObject("Msxml2.XMLHTTP");


I believe that this line assumes that an ActiveX server names "Msxml2"
is installed and properly registered on your computer. Are you sure
that this has been done?

--
Tim Slattery
Sl********@bls.gov
Nov 23 '05 #5
So...I figured it out...it turns out that the problem wasn't the object
I thought, but rather that the response coming back into the
makeRequest function wasn't coded as XML. Safari and Firefox had no
problem with it because of the line ...

http_request.overrideMimeType('text/xml');

....but IE Explorer wasn't so forgiving. I changed the response type to
"text/xml" server side, and all's well.

Or not quite well: now, in IE Explorer, the code runs once and once
only. I have to reload the page to get it to run again.

It'd be nice to have some pointers on this issue, too!

Thanks for all your replies!

--Brent

Brent wrote:
This AJAX stuff is all new to me. To try it out, I borrowed this code
from a website:

Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dave Hammond | last post: by
3 posts views Thread by =?Utf-8?B?QmFkaXM=?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.