Chee mun Low
Chee mun Low

Reputation: 107

Failed to invoke javascript, $ is undefined

i failed to pass the value to my script, anyone can tell me what is my mistake ?

output

Microsoft JScript runtime error: '$' is undefined

my javascript function

function setSessionValue(key, value) {

    $.post('setSession.aspx?key=' + key + '&value=' + value);        
}

button to call for function

asp:LinkButton ID="lnkname" runat="server" Text='<%#Eval("movieTitle") %>' Width='500px'
CommandName="cmdLink" PostBackUrl='~/videotest.aspx'` 
OnClientClick="setSessionValue('itemID','3345');"

Upvotes: 0

Views: 505

Answers (4)

gdp
gdp

Reputation: 8232

Also make sure you have imported jquery first before any scripts using it.

Upvotes: 0

Amar Palsapure
Amar Palsapure

Reputation: 9680

The most probable reason would be,

  1. You have forgot to import the jQuery library or it is failing to download at client machine.
  2. You have used $ syntax before importing the jQuery.

The syntax should look like this

 <script type="text/javascript" src="SOURCE OF YOUR JQUERY.JS FILE">
 <script type="text/javascript">
     function setSessionValue(key, value) {
          $.post('setSession.aspx?key=' + key + '&value=' + value);        
     }
 </script>

Hope this helps you.

Upvotes: 0

Sunil Kumar B M
Sunil Kumar B M

Reputation: 2795

include jquery library in your asp page

Upvotes: 1

Hemant Metalia
Hemant Metalia

Reputation: 30648

have you included jquery js files in your page?

<script 
     type="text/javascript"          
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>

Upvotes: 2

Related Questions