$(“#form1”).validate is not a function

最后都变了- 提交于 2019-12-12 06:07:13

问题


<script type="text/javascript">
<!--
$(document).ready(function() { 
      $("#form1").validate({ 
        rules: { 
         budget: {
            required: true,
             minlength:3
        } ,
       duration: {
            required: true,
            digits:true
        }, 
         town: {
            required: true,
             minlength:2

        },

       content: {
            required: true,
            minlength:300 

        }
         }, 
        messages: { 


        } 
          }); 
        });
        -->
</script>

Two jquery files are included.

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

are included. There is nothing wrong with the inclusion.

I got an error message

$("#form1").validate is not a function What's wrong?


回答1:


Put the jQuery script tag before the script tag for validation

I just encountered this extremely frustrating error and lost the better part of an hour to it, for lack of a workable answer online. I confirmed in Firebug that I was hitting the CDN for both jQuery and validation.

In the end, changing this:

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script>

to this:

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>

was all I needed.




回答2:


I had this same issue. It turned out that I was loading the jQuery JavaScript file more than once on the page. This was due to included pages (or JSPs, in my case). Once I removed the duplicate reference to the jQuery js file, this error went away.




回答3:


I had the same issue, and yes I had my jquery included first followed by the jquery validate script. I had no idea what was wrong. Turns out I was using a validate url that had moved. I figured this out by doing the following:

  1. Open firefox
  2. Open firebug
  3. Click the NET tab in firebug. This will show you all the resources that get loaded.
  4. Load your page.
  5. Check the loaded resources and see if both your jquery & jquery.validate.js loaded.

In my situation I had a 403 Forbidden error when trying to obtain (http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js which is used in the example on http://rocketsquared.com/wiki/Plugins/Validation ).

Turns out the that link (http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js) had moved to http://view.jquery.com/trunk/plugins/validate/jquery.validate.js (Firebug told me this when I loaded the file locally as opposed to on my web server).

NOTE: I tried using microsoft's CDN link also but it failed when I tried to load the javascript file in the browser with the correct url, there was some odd issue going on with the CDN site.




回答4:


youll need to use the latest http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js in conjunction with one of the Microsoft's CDN for getting your validation file.




回答5:


Had the same issue; validated HTML & found I was missing a name="email" attribute from an <input />. Always validate the HTML to be positive your HTML is valid. After I added it, validate() worked perfectly.




回答6:


Make sure that jQuery is using the $ variable, and its not another javascript framework.

Check your doctype: Validate your html, sometimes browsers don't see stuff in quirks mode, or when they encouter malformed html.

Also ensure that jquery.validate.js file is correct.

You can download it below:

http://bassistance.de/jquery-plugins/jquery-plugin-validation/




回答7:


Probably the browser first downloaded the validade script and then jQuery. If the validade script be downloaded before loading jQuery you'll get an error. You can see this using a tool like firebug.

Try this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
    function LoadValidade() {
        var a = false;
        try {
            var teste = $('*');
            if(teste == null)
                throw 1;
        } catch (e) { 
            a = true; 
        }

        if (a){ 
            setTimeout(LoadValidade, 300);
            return;
        }

        var validadeScript = document.createElement("script");
        validadeScript.src = "../common/jquery.validate.js";
        $('head')[0].appendChild(validadeScript);
    } 
    setTimeout(LoadValidade, 300);
</script>



回答8:


Check if you use Proxy.

I've got this problem in Mozilla Firefox, I thought it's some issue related to the Firefox itself. Later I found out that I am using a proxy server. When I unchecked the proxy, everything got fine.




回答9:


my solution to the problem: in footer add <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>




回答10:


If you had a link I could look to see what the issue is but here are a couple questions and things to check:

  • Is the ID for your form named "form" in the HTML?
  • Check to see if messages are required, maybe there is some imbalance in parameters
  • You should also add the 'type="text/javascript"' attributes where you are getting jQuery from Google

Also, if you're going to use the Google CDN for getting jQuery you may as well use Microsoft's CDN for getting your validation file. Any of these URLs will work:

  • http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js
  • http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js
  • http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate-vsdoc.js



回答11:


Maybe silly, but check that you inline script is AFTER you include the script tags.




回答12:


I had this issue, jquery URL was valid, everything looked good and validation still worked. After a hard refresh CTL+F5 the error went away in Chrome.




回答13:


In my case i moved the validate part outside of the document ready function and it works fine for me. I hope it would work for u...

 $(document).ready(function () {
   // paste validate function outside of the document ready function...
});

    $('#form1').validate({

        rules: {
            English_Name: { required: true, minlength: 3 },
            Arabic_Name: { required: true, minlength: 3 },
            latitude: { required: true, min: 16, max: 32, number: true },
            longitude: { required: true, min: 32, max: 52, number: true },
            EmployeeID: { required: true },
            PaymentTypeID: { required: true },
            BusinessTypeID: { required: true },
            SalesTypeID: { required: true },
            OutletLength: { required: true },
            OutletWidth: { required: true },
            CONTACT_PERSON: { required: true },
            MOBILE_NO: { required: true, minlength: 9, maxlength: 13, digits: true },
            TRADE_LIC_DATE: { dateValidation: true },
            CreditLimit: { min: 0, max: 2000000 },
            CreditPeriod: { min: 0, max: 365 },
            EMAIL_ADDRESS: { email: true },
            BusinessClassID: { required: true },
            CustomerClassificationID: { required: true },
            LicenseTypeID: { required: true }
        },
        message: {
            English_Name: {
                required: ''

            },
            ToDate: {
                required: ''

            }




        },
        submitHandler: function (form) { // for demo

            $.ajax({
                type: 'POST',
                url: '/sfa/Verification/SaveDataInDatabase',
                data: $('form').serialize(),
                beforeSend: function () {
                    $('.submitBtn').attr("disabled", "disabled");
                    $('.modal-body').css('opacity', '.5');
                },
                success: function (msg) {


                    $("#form1").trigger('reset');
                    $('.modal').modal('hide');
                    $('.submitBtn').removeAttr("disabled");
                    $('.modal-body').css('opacity', '');
                }
            });
        }
    });


来源:https://stackoverflow.com/questions/32222476/how-to-fix-uncaught-typeerror-validate-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!