0

I already had my Jquery validate function, but something happen and start showing me this error

<script>
    $(document).ready(function () {
        //Uncaught TypeError: undefined is not a function
        $("#commentForm").validate();
    });
</script>

I using fiddle to test a simple example, I add

jquery-1.8.3.min.js
jquery.validate.min.js

And works ok. Adding the error labels to the right side of each field

So I create a new basic MVC site using my visual 2013 studio . And include the scripts. And the same fiddle sample

<script src="~/Scripts/jquery-1.8.3.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>

But still say .validate(); is undefine. The weird part is field validation tooltip works, but right side labels doesn't. enter image description here

NOTE: Isn't duplicated. In my MVC code I already include jquery.validate.min.js

Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
  • There is nothing wrong with the code you've posted, so there is nothing we can do for you. It says that error because you're apparently not including the plugin properly. Did you upload the files to the `~/Scripts/` directory? Are you sure that's the correct location? – Sparky Feb 12 '15 at 17:48
  • Opening the console shows: **Mixed Content: The page at 'https://jsfiddle.net/dropyghost/sb21y2bv/2/' was loaded over HTTPS, but requested an insecure resource 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js'. This request has been blocked; the content must be served over HTTPS.** – Ryan Wheale Feb 12 '15 at 17:48
  • @RyanWheale, [the OP's jsFiddle](https://jsfiddle.net/dropyghost/sb21y2bv/2/) is working fine for me. But the OP is not asking about his jsFiddle because it's working for him too; he wants to know why he can't get it working in his project. – Sparky Feb 12 '15 at 17:50
  • @Sparky Why you mark my question as duplicate? My code show I Include `` in my MVC – Juan Carlos Oropeza Feb 12 '15 at 18:14
  • It's a duplicate because it's the same problem and there is nothing here that we can solve for you. It's up to you to properly include the script files, otherwise it would not say `error: validate is undefined`. – Sparky Feb 12 '15 at 18:18
  • @Sparky how can i be putting wrong the script? isnt just drag and drop in the page.cshtml ? Also as i mentioned, my page was already working and start to fail. I create a new empty project to isolate the problem. – Juan Carlos Oropeza Feb 12 '15 at 18:21
  • Did you upload the files to the ~/Scripts/ directory? Are you sure that's the correct location? Does your console give you any 404 errors? – Sparky Feb 12 '15 at 18:23
  • @Sparky also, in your suggested asnswer the OP missed the jquery.validate.js, I didnt. That is why i think i deserve the chance other take a look to my question. But marking this question as duplicated hurt my chances to find an answer. – Juan Carlos Oropeza Feb 12 '15 at 18:24
  • @Sparky Yes, the proof is the jquery works ok. Also the Jquery validate work for the field when you try to lose the focus. Is the `validate()` function isnt define. So the label on the right side doesnt appear when submit occurs. – Juan Carlos Oropeza Feb 12 '15 at 18:25
  • @Sparky You are right on that point. I add a picture for improve my question. But still my point is this isnt duplicated as I try to explain i did include the script. – Juan Carlos Oropeza Feb 12 '15 at 18:29
  • Now this is not making any sense. How can it be working if you're not getting the labels and `validate` is undefined? If you have a `validate undefined` error, then the jQuery Validate plugin is NOT installed at all. – Sparky Feb 12 '15 at 18:30
  • @Sparky I know is weird, The error is `Uncaught TypeError: undefined is not a function` just in the validate line. I try to isolate the issue in a new single project. And still have the error. – Juan Carlos Oropeza Feb 12 '15 at 18:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/70812/discussion-between-juan-carlos-oropeza-and-sparky). – Juan Carlos Oropeza Feb 12 '15 at 18:37
  • @Sparky please could you remove the Duplicated tag? – Juan Carlos Oropeza Feb 12 '15 at 18:41
  • That picture shows default HTML5 validation as per the browser, that has nothing to do with your broken jQuery Validate. – Sparky Feb 12 '15 at 18:51
  • See: http://stackoverflow.com/a/26700277/594235 – Sparky Feb 12 '15 at 19:32
  • @Sparky Yes, I got that part. Now why MVC doesnt like the `` ? – Juan Carlos Oropeza Feb 12 '15 at 20:14
  • Again, I've asked this three times: Are you absolutely sure that `~/Scripts/` is the correct location? There are no 404 errors in your console? – Sparky Feb 12 '15 at 20:33
  • @Sparky, No error on the console, you can see the picture the only error. – Juan Carlos Oropeza Feb 12 '15 at 20:36
  • I'm sorry, there is nothing anybody can do here with what you've shown. **The code you've posted is correct and it works.** Use your console to inspect the browser source (not the DOM) to verify that the scripts includes are showing in the code. – Sparky Feb 12 '15 at 20:43
  • I found my problem: In mvc you need to put your scripts in a script section `@section Scripts { }` – Juan Carlos Oropeza Mar 02 '15 at 15:05

0 Answers0