I have this conceptual question about ajax that I’m not sure if I understand. Say I have a page called original and in original, I use ajax to load another page into orignal called ajaxPage. My question is if original defined a javascript method called testing(), then can ajaxPage use testing()?
To me, it seems that ajaxPage should be able to use testing() because after ajaxPage becomes part of the original page, there is nothing stopping it from having a reference to testing(). But this also means that when coding the ajaxPage, you have a reference to testing() but with just the ajaxPage itself, there is no testing() method defined.
Does anyone have any insight as to what should happen? and why it happens?
Any script loaded into the DOM, whether by AJAX or other means, will have access to code already loaded. See demo: http://jsfiddle.net/JAAulde/uCg75/2/
And yes, if you were to load the AJAX content into any context in which
testing()is not defined (since it is not defined within itself) you would get an error for reference to undefined function.