views:

637

answers:

2

Hi,

VS2008.

I have an MVC app and I dynamically rendering html for a control I am building.

I have written some javascript and put in a .js file.

My master page has a refernce to my jquery js file.

A user control then calls my code to render html.

My js file uses JQuery.

When i debug i am getting an "undefined" error when printing the statement in Immediate Window.

Is this because my js file does not reference the Jquery JS file?

If so how do I reference it??

Malcolm

A: 

If you don't reference jQuery then yeah.

Make sure you include it with:

<script type="text/javascript" src="/dhtml/jquery-1.3.1.min.js"></script>

Immediate window is for server side code.

Grab Firebug for firefox add-on for javascript output and check out the console.log functionality

jQuery without Firebug is painful

Chad Grant
A: 

Malcom,

Make sure that your jquery reference is resolving -- you can use firebug, or your can just test the url out while the web server's up. I definitely agree that having firebug around when doing JS/UI development is a must!

Look for the script reference when you load your page... You may copy the url out and test by pasting in the browser... for example, if you view source on your web site's url (http://localhost:1234/) and see:

<script type="text/javascript" src="scripts/jquery-1.3.2.js"></script>

enter http://localhost:1234/scripts/jquery-1.3.2.js in your browser and see whether you receive the JS content (or are prompted to download).

Hope this helps.

Seth

Yes the jquery js and my js are referenced....but when i debug my js should that file have an explcit reference to the jquery in it, do you understand my meaning???
Malcolm
If you've referenced JQuery before your js file, you shouldn't explicitly need to reference it from within.