I am working on a bug, where there is a request made and then an updated view is returned with an inline script block to update some of the view. I was getting an odd reference error with $ not being defined. After some investigation in chrome, I discovered that in the context that appears to exist at the very instant the reference error occurs there is no $ defined, but window.parent.$ is defined.
Method of discovery:
I basically had Chrome break on unhandled errors, which naturally brought me to a callstack of one call that was just the anonymous function. Usually the console seems to use a context consistent with the breakpoint, but in this case I had to use the watch window to see what was defined and what was not. I observe this behavior in all of Firefox, Chrome, and I.E.
The fact that the request is an AJAX request is probably irrelevant. When HTML is appended to an already existing DOM, and it has inline script tags – do these inline script tags execute within their own child window context similar to an iframe?
We are injecting the returned response via jQuery, which I am assuming may be handling the execution. Could jQuery be creating a new child window context?
In what situations outside of an IFrame is a child window context used?
The problem actually did end up being an IFrame. Someone was using a callback within a callback using a “ajaxSubmit” extension which used an IFrame internally. My assumption about IFrames not being used was incorrect.