views:

67

answers:

3

i am using asp.net mvc in that i am using partial views but i get the following error

Error: $ is not defined Line: 159

it is for the java script its not getting reference. i included the java script in site.master

     <script src="../../Scripts/jquery-1.2.6.js" type="text/javascript"></script>
     <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
     <script src="../../Scripts/ui.core.js" type="text/javascript"></script>
     <script src="../../Scripts/ui.datepicker.js" type="text/javascript"></script>

first js is for partial view. and my function is:

<script type="text/javascript">
    $(document).ready(function() {
        var dt = { changeYear: true, yearRange: "-6:+6" }
        $("#FromDate").datepicker(dt);
    });
</script>

so can you tell me how to resolve reference problem.because of that date picker is also not working and partial views also not working but on local host it works fine but on server nothing is working. i also used src="<%= Url.Content("~/Scripts/XXXX.js")%>" but still its not working on server. thank you.

+2  A: 

It's one of two things:

  1. You're including jquery-1.2.6.js and jquery-1.3.2.js. One is messing with the other.

  2. The files are not being loaded at all. Can you use firebug and look at the net tab to see that they are successfully be loaded?

sdolan
its working on localhost properly it gives problem when i deploy it on server. plz tell me solution if you konw all js files are properly loaded thanks
Renu123
So the js files do *not* get loaded correctly when you deploy it to the server? Try using absolute paths as mdresser mentioned.
sdolan
i also tried this but still its not working
Renu123
+1  A: 

can you check what happens when you replace $ with jQuery? does it works. Also try doing alert(jQuery) if it is undefined that means your libraries are not loaded and you need to check for your paths.Also as mentioned try using one latest version of jQuery than two.

sushil bharwani
+2  A: 

The problem will be with the path to the scripts I think. Where you have

src="../../Scripts/jquery-1.2.6.js"

you probably need to change this to something like

src="/Something/Scripts/jquery-1.2.6.js"

you could also try referencing an external version (as SO does).

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
mdresser
i also tried this but still its not working
Renu123