Discovered from the dojo-list that when using "eval" in Firefox, the
script is always evaluated in the scope of the window object, but in
IE7, the script is evaluated in the scope of the function in which it is
called. Since I'm using dojo to evaluate the DWR scripts, they were all
being evaluated in the context of dojo's "dj_eval" function, ala the bug
documented here:
http://trac.dojotoolkit.org/ticket/744 Thus, the
DWREngine and services I was including weren't available globally.
On the DWR side, the way DWR generates JavaScript could be changed to
prepend "window." to the functions/objects it creates -- this would
declare the DWR stuff in the window scope so it could be modularly
included/imported as I'm doing.
If you're using dojo, an easier workaround in the meantime is to change
the dj_eval function as suggested in the above link.
Thanks!
Jim
Jim wrote:
Hello all,
I'm working on a relatively simple dojo module that allows for
lazily-loading DWR services. Reason: if I have a widget that requires
a DWR service, I don't want to have to make sure the enclosing HTML
page has the appropriate script tags -- I want to say inside my dojo
module: mycompany.dwr.loadDWRService("WidgetDWRService");
My solution so far works great in FF2.0, but I'm having trouble
getting it to work in IE7 -- I think the DWR JavaScript files aren't
evaluating correctly in IE7.
Here is my module; hoping someone familiar with dojo (I'm using 0.4.1)
and DWR (I'm using 1.1.3) can help me figure out the issue and/or a
workaround:
================================
dojo.provide("mycompany.dwr.common");
mycompany.dwr.loadDWREngine = function() {
if (! dj_undef("DWREngine")) {
dojo.debug("Engine already loaded");
return;
}
dojo.debug("Result of load: " +
dojo.hostenv.loadPath("../../dwr/engine.js"));
if (dj_undef("DWREngine")) {
dojo.debug("DWREngine doesn't exist -- loading failed");
} else {
dojo.debug("DWREngine successfully loaded");
}
};
mycompany.dwr.loadDWRService = function(/*String*/dwrName) {
// First trying to load the DWREngine
mycompany.dwr.loadDWREngine();
if (! dj_undef(dwrName)) {
dojo.debug(dwrName + " already loaded");
return;
}
dojo.debug("Result of service load: "
+ dojo.hostenv.loadPath("../../dwr/interface/" + dwrName + ".js"));
if (dj_undef(dwrName)) {
dojo.debug(dwrName + " doesn't exist -- loading failed");
} else {
dojo.debug(dwrName + " successfully loaded");
}
};
================================
In my dojo widget, I'm making the following call:
mycompany.dwr.loadDWRService("WidgetDWRService");
In Firefox 2.0.0.1, this is the dojo.debug output from above:
Result of load: true
DWREngine successfully loaded
Result of service load: true
WidgetDWRService successfully loaded
Engine already loaded
In Internet Explorer 7.0.5730.11, this is the dojo.debug output from
above:
Result of load: true
DWREngine doesn't exist -- loading failed
Result of service load: true
WidgetDWRService doesn't exist -- loading failed
Anyone have any ideas why this would work perfectly in Firefox but not
in IE7, and how I could go about debugging it? I know IE7 is a little
awkward with AJAX support with its ActiveX and native XMLHttpRequest
objects each being a little different, but I don't know enough about
that to know if it's what the issue is here.
Thanks much,
Jim
|