[jQuery] Development pattern for large projects

[jQuery] Development pattern for large projects


I am a Java developer who is working more and more with javascript. I
love Jquery, but am unsure how to architect a largish project.
Each widget I make will need to communicate with the server, so I have
put each widget in its own directory and have it pull dynamic content
from jsp/php files in the same directory.
When I want a page (in another directory) to include the widget, I
have taken the approach of including the appropriate .js file using a
<script> element in that page, creating the objects defined within it,
then having the widget write its content to a div on the current page.
The problem I am running into is that the objects created from the
imported .js files don't seem to know which directory they came from
anymore, so they cannot find the server side files they need to
communicate with.
What is the best way to deal with this? Is there a better way to
architect this? Is there a way that objects loaded from a .js file can
know what their original source directory is?
- Steve