Forum Moderators: open
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!
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"")
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]
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?