简体   繁体   English

TypeError:jQuery(...)。validate不是函数

[英]TypeError: jQuery(…).validate is not a function

I am bringing a dynamic html content on to another html content. 我将动态html内容带到另一个html内容。 This is basically an edit form html view, but when I try to validate the from, it gives me "TypeError: jQuery(...).validate is not a function" error. 这基本上是一个编辑形式的html视图,但是当我尝试验证from时,它给了我“TypeError:jQuery(...)。validate是一个函数”错误。 I am using jQuery 1.6.2 version. 我使用的是jQuery 1.6.2版本。

function validate_edit_venue() {
    jQuery('#venue_edit_form').validate({
        rules: {
            venueName: {
                required: true,
                minlength: 1,
                maxlength: 50
            },
            venueDescription: {
                required: false,
                lettersonly: true,
                maxlength: 150
            },
            venueType: {
                required: true
            }

        },
        messages: {
            venueName: {
                required: "Venue name is required",
                minlength: "Minimum 1  character required",
                maxlength: "Should not exceed 50 characters"
            },
            venueDescription: {
                maxlength: "Should not exceed 150 characters"
            },
            venueType: {
                required: "Please select a venue type"
            }

        }
    });
}

This is my jQuery validation. 这是我的jQuery验证。 I am calling this function at the jQuery edit form script. 我在jQuery编辑表单脚本中调用此函数。 Can anyone help me with this issue? 任何人都可以帮我解决这个问题吗? This question maybe a duplicate but most of them are due to the jQuery version issue, so I couldn't obtain a proper answer through them. 这个问题可能是重复的,但大多数是由于jQuery版本问题,所以我无法通过它们获得正确的答案。

      jQuery('#venue_edit_save').live('click', function(){

       validate_edit_venue();

       if(jQuery("#venue_edit_form").valid())
       {
            var directory_id = jQuery(this).attr('directory_id');
            var venue_type = jQuery(this).attr('venue_type');
            var venueName = jQuery('#venue_name').val();
            var venueDescription = jQuery('#description').val();
            var venueType = jQuery('#venue_types option:selected').val();
            var venueImage = jQuery('[name="profile_image'+directory_id+'"]').val();
            jQuery.blockUI();
            jQuery.ajax({
                    type: 'POST',
                    cache: false,
                    dataType: 'json',
                    url: baseurl+'catalog/catalog/action/venues/edit_venue',                
                    data:{'directory_id':directory_id,'venueName':venueName,'venueDescription':venueDescription,'venueType':venueType,'venueImage':venueImage},                

                    success: function(data)
                    {                    
                        if(data.status == 'success')
                        {
                        /*if(venue_type == venueType)
                        {
                            jQuery('#Venue_'+directory_id).replaceWith(data.html);
                        }
                        else
                        {
                            location.reload();                              
                        }*/
                            jQuery('#Venue_'+directory_id).replaceWith(data.html);
                            show_messages(data.status,data.msg);
                            setTimeout(jQuery.unblockUI);
                            jQuery('#edit-dining-venue-block').hide();
                            location.reload();
                        } 
                        else if(data.status == 401)
                        {
                            redirect_login_timed_out();                         
                        }
                    /*else
                    {
                        show_messages(data.status,data.msg);
                        setTimeout(jQuery.unblockUI);
                        jQuery('#edit-dining-venue-block').hide();
                    }*/
                    },
                    error:function (jqXHR)
                    {
                        if(jqXHR.status == 401)
                        {
                            redirect_login_timed_out();
                        }
                        setTimeout(jQuery.unblockUI);
                    }

            }); 
       }
  });

   // Hiding the edit venue view when clicking the cancel button
   jQuery('#venue_edit_cancel').live('click', function(){

       jQuery('#edit-dining-venue-block').hide();

   });              

});

This is where the error occurs. 这是发生错误的地方。 This jQuery saves the edited info: while validating. 这个jQuery保存编辑的信息:验证时。

Thanks. 谢谢。

This appears to me the case of your ajax call returning script tags. 在我看来你的ajax调用返回脚本标签的情况。

I think what happens here is your ajax call returns DOM along with another jquery script tag which overwrites your jquery and you loose all your plugins, and other bad things happen 我想这里发生的是你的ajax调用返回DOM以及另一个jquery脚本标记,它会覆盖你的jquery并且你松开所有的插件,并发生其他坏事

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM