-1

I am trying to added a js file. But I get error:

Uncaught ReferenceError: $ is not defined 

Index.cshtml

<div id="body">
    <ul id="contacts">
    </ul>
</div>
<div>
    <ul id="comdata">
    </ul>
</div>
<script src="@Url.Content("~/Scripts/handlers.js")"></script>



**handler.js**
$(function(){
     $.getJSON('/api/contact/', function(data){
        $(data).each(function(i, item){
             $('#contacts').append('<li>' + item.Name + '</li>');
        });
    });
});
mrd
  • 1,985
  • 3
  • 21
  • 47
  • Or [Uncaught ReferenceError: $ is not defined?](http://stackoverflow.com/questions/2075337/uncaught-referenceerror-is-not-defined), both of which are the first web search results on the actual error. Please show some research effort. – CodeCaster Sep 19 '14 at 14:33
  • try to add jquery file. – Yehia Elhawary Sep 19 '14 at 15:05

1 Answers1

3

One reason that one would get this error is that they didn't include jQuery. Please double check to make sure that jQuery is included.

hichris123
  • 9,735
  • 15
  • 51
  • 66
E3E
  • 33
  • 5
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – AHiggins Sep 19 '14 at 18:22
  • Thanks for this constructive comment. Although i might think that would be an answer. – E3E Sep 20 '14 at 22:27
  • 1
    It might be helpful to look at the revision history of your answer: as you originally wrote it, it sounded more like a request for clarification from the author, rather than a suggestion of a possible solution. When it came up in a review queue, I (and others) marked it as such: questions belong in comments. @hichris123 then edited your answer (something I actually didn't have the specific jquery knowledge to do) to turn it from a question ("have you tried jquery") to an answer ("not including can cause this error, make sure you have it"). Does the difference make sense? – AHiggins Sep 22 '14 at 14:16