tags:

views:

41

answers:

1

Hi, I'm using Zend Framework and on one of my forms I have a ZendX JQuery form element. When I run the action that instantiates the form like this:

.../controller-name/action-name

the form element works fine.

But when I append a parameter to the url, i.e.

.../controller-name/action-name/parameter

the form element does not work and firebug tells me that '$ is not defined.'

Does anyone have any idea on what I should do?

+2  A: 

It sounds like your jQuery include is relative, like this:

<script src="../js/jQuery.js" type="text/javascript"></script>

This depends on the page being at a certain level in the site, which is changing when you add another directory (as far as the browser is concerned). Whatever the path, make sure it's relative to the root of the site, for example:

<script src="/js/jQuery.js" type="text/javascript"></script>

Starting with a / means it's relative to the root of the site. Or, you can include it from a CDN, like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> 
Nick Craver
Apparently I just needed to re-position <?php echo $this->jQuery(); ?> AFTER the script inclusion. Thanks for the reply though. :)
@user429148 - I don't follow...your question stated it works without the parameter, it shouldn't work at all if you're calling jQuery before including it, in any situation...
Nick Craver
I have forgotten I've included a local path in my bootstrap and I also have a CDN source in my layout.phtml file. I ran my program on a machine without internet connection and encountered the same problem. So I discovered my local path was relative like how you described.
@user429148 - Ah that makes more sense, be sure to either add that as an answer or accept this one then, to close out the question, via the check-mark beside the answer (be sure to do this for you future questions as well, it helps the next guy/girl with the same issue finding this).
Nick Craver
Will do that, thanks again. :)