Object doesn’t support property or method while executing new XMLHttpRequest from CRM 2011/2013 html resource

Recently I faced this weird error

Object doesn’t support property or method

while My CRM 2013 html web resource invoked from a CRM ribbon button was trying to execute the below method required before making the CRM Ajax based call.

function GetRequestObject() {
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest;
}
else {
try {
return new ActiveXObject(“MSXML2.XMLHTTP.3.0”);
}
catch (ex) {
return null;
}
}
}

 

The error was happening exactly at the statement “return new window.XMLHttpRequest;

I had the same code working in CRM Online environment but after porting it to the On-Premise I got this error. for some host machines it was not the issue, where as for majority of my client machines this issue was coming.

first as a solution I skipped the new window.XMLHttpRequest statement and used the “return new ActiveXObject(“MSXML2.XMLHTTP.3.0″);” it did work for one of my OData call but it failed with the same error in another OData call, this time it was in the standard  JQuery library, inside of which they have used the statement “new XMLHttpRequest()”.

Since the code was working in another of my web resource I was not sure what exactly could be the problem,

but after concentrating a bit between these two Working and Non-Working versions of my HTML files, I found something that caught my attention, guess what , By mistake I had kept all my java script code inside the <head></head> tag, which was the root cause, as the window was not completely formed while my Java script are getting executed.

after moving the java scripts to the Body (<body></body> of the Html page, it worked perfectly.

I was so amazed with this discovery of mine, though it took me a lot of time.

Advertisements
This entry was posted in CRM 2011, CRM2013, java script, JQuery, OData and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s