Forum Moderators: open

Message Too Old, No Replies

MSXML2 automation server cannot create object

loads via ASP but NOT javascript

         

jzeiger

10:01 pm on Nov 19, 2004 (gmt 0)

10+ Year Member



I have created a web page on a Windows 2000 Server.

I can successfully instantiate the MSXML2 object via ASP. But the javascript that "does the same thing" fails. I receive the "automation server cannot create object" error. *I know that I can upgrade to version 4 and this "might" fix the problem. But I assume that the older version is more stable than the latest and greatest MSXML.

Here is the Javascript that does not work:
var objXMLHTTP = new ActiveXObject('MSXML2.ServerXMLHTTP');

Here is the ASP code that works:
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
' *** I do my processing here
set objXML = nothing

Can anybody lend any insight? Tks much!

Bernard Marx

9:16 am on Nov 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you executing the Javascript on a webpage, or on the server?

jzeiger

2:16 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



My js is not being compiled. It runs client side.

Bernard Marx

2:17 pm on Nov 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah. It's still on the server.

If I'm not mistaken, you can still use the server object when scripting ASP in JScript. So the code would be:


var objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
// Do your processing here
objXML = null;

This is based in the reasoning that it's the same as WSH, where there are two ways to instantiate a COM object, eg:


FSO = new ActiveXObject("Scripting.FileSystemObject")
// or
FSO = WScript.CreateObject("Scripting.FileSystemObject"")

The first could be called a 'native' method, the other one is offered by WScript.
WScript is paralleled by Server in the case of ASP.

Bernard Marx

2:23 pm on Nov 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You managed to post before my answer, which now doesn't make sense.

If you are doing this client-side then I guess you are trying to instantiate the wrong object (?).

How's about something along the lines of this one, which attempts Moz browsers first, then goes through the possible versions of XMLHTTP for Microsoft.

[pre]
var xml;
try
{
// Mozilla Browsers
xml = new XMLHttpRequest();
}
catch(ex){}

// IE Browsers
var progIDs = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
for(var currentProgID = 0;currentProgID < progIDs.length;currentProgID++)
{
try{ xml = new ActiveXObject(progIDs[currentProgID]); }
catch(ex){}
}
[/pre]

jzeiger

3:06 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



I can't run a test at this moment.

But, if my web page is browsed from the server itself (not client), I think that the object should be successfully created in javascript.

I say this, since my ASP, that instantiates the SAME object, works.

Or, wait a second here...did Microsoft do something so that you MUST use Jscript?