IE is the coolest browser on Earth. Really. It's like Vanilla Ice. So incredibly cool that it had to fade away in order to let other feeble browsers like Firefox get some air time. With that being said I ran into a real weird issue with IE that didn't make sense to me. Imagine the following code.
<cfajaxproxy cfc="test" jsclassname="mycfc">
<script>
var mycfc = new mycfc();
alert(mycfc);
</script>
All this code does is create a proxy between the client side and a CFC named test. The proxy's class will be called mycfc. Note then that I make an instance of the proxy with a variable called mycfc.
When run, you get the oh-so-helpful "Object expected" error. Luckily I didn't have any tools like Firebug to help me. I was truly confused as this same simple code also worked in Firefox. Obviously this is some flaw in Firefox.
Turns out the issue was rather simple. The error derived from the fact that I used a variable (mycfc) with the same name as the proxy class. In retrospect, that actually was a bad idea probably. I really should have named it a bit nicer. In fact, consider this code:
<script>
var mycfc = new mycfc();
alert(mycfc);
var mycfc2 = new mycfc();
alert(mycfc2);
</script>
This will break in Firefox as well. It seems like that first line 'breaks' the proxy. For IE it breaks immediately, and for Firefox it breaks after the assignment. (Ok, so all kidding aside - I actually prefer IE noticing the issue sooner.)
Just something to watch out for folks.
Archived Comments
Ray, you probably know, but if not, you can find Firebug-like tools in the IE Developer Toolbar (google for it). Equally useful for IE work is HTTP Fiddler, for debugging HTTP traffic between client server.
I'll second Fiddler. It has helped me debug several IE-only errors that were causing me grief.
I'm not a JS expert, but I think what is happening is that you are overwriting the mycfc "class" with your instance of it.
From what I understand, since JavaScript is a prototype-based language, there are no "classes"; everything is an object ( http://developer.mozilla.or... ). You can create class like objects, but they exist in the same space as instances of it.
From what I can see, this generated line:
var _cf_Test=ColdFusion.AjaxProxy.init('/test/cfajaxproxy/Test.cfc','mycfc');
will pass in the string 'mycfc', and create a "class" like object called 'mycfc' in the global, window scope. This means that "mycfc" exists as an object prior to your code.
So, this line:
var mycfc = new mycfc();
will actually create an "instance", and overwrite the "class" object.
It's interesting that IE seems to look ahead and freaks out when it sees this and just fails silently.
I generally try to capitalize the values i put in the jsclassname, so that it leaves the possibility of writing:
var myCFC = new MyCfc();
This article provides a decent summary of how to do "oo" like programming with JavaScript, such as creating "class" like objects that have constructors:
http://www.digital-web.com/...
I had a similar issue, I ended up tracking it down to the fact that my cfc had a remote function called delete (i.e. <cffunction name="delete" output="false" access="remote">)
When I renamed the delete function Internet Explorer worked.
Strange, hope this helps someone else
Cheers for this, Ray, you just ended what was shaping up to be a painful day of IE-only debugging. Thanks for saving me some agony!
Raymond thanks a million times, for posting this!!