Static News Archive



   (27-Aug-07 9:01)  automation server can't create object
In Internet explorer, I received the following error when trying to use an activeX object for ajax:

"automation server can't create object"

This is apparently related to security settings. However, it's unreasonable to expect users to adjust their security settings for your webpage :)

So put a try catch around your activeX object creation:

function CreateRequestObject()
{
var ajaxRequestObject;
try {
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer")
ajaxRequestObject = new ActiveXObject("Microsoft.xmlHttpObject");
else
ajaxRequestObject = new XMLHttpRequest();
}
catch (e) {

}

return ajaxRequestObject;
}


What you will find is that now, you will not get a request object - so in the case where your request object == null, you will have to deal with the user using old postbacks.
However, you also won't get a javascript error.

	xmlRequest = CreateRequestObject(); //using code above ^
var form = document.getElementById('myForm');
//check if we can do an ajax post...
if (xmlRequest == undefined) {
//we can't, so submit the form using traditional means...
form.submit();
}
else {
//we can, so do an ajax submit...
var postString = "";
//build postString

//do some kind of ajax post
sendRequestToServerPage(xmlRequest, 'serverSideSubmit.php', postString, submitCallbackFunction);
}


As an aside - one small quirk of the try {..} catch {..} in iexplore is that the variable in the catch parentheses must be 'e' - otherwise, it seems that the try catch doesn't work at all.


-Rob-
Post a comment     

<-  (21-Aug-07 10:34)  Geekgear is live... (29-Aug-07 9:52)  Calling Webservices ...  ->













(sitemap)