1

由于 jquery,由于某些奇怪的原因,我收到错误“预期对象”,这不会“提交”表单或将数据输入数据库。

没有jquery,数据可以输入到数据库中。但现在没有了。

我主要使用 jquery 来验证 asp.net 控件。


roosteronacid,验证工作非常好, id 属性也是一样的。提交只是没有执行服务器端代码,我不知道是什么问题。

编辑:

这是jQuery代码:

 <script type="text/javascript">
        $(document).ready(function() {
            // add custom validation methods
            $.validator.addMethod('phone', function(value, el, params) {
                return this.optional(el) || /^[0-9,+,(), ,]{1,}(,[0-9]+){0,}$/.test(value);
            }, 'Please enter a valid phone number');

            $.validator.addMethod('numbers', function(value, el, params) {
                return this.optional(el) || /^[0-9]+$/.test(value);
            }, 'Invalid entry. Only Numeric is allowed.');


            $.validator.addMethod('domainurl', function(value, el, params) {
                return this.optional(el) || /^(http\:\/\/(?:www\.)?[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*(?:\.[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*)*\.[a-zA-Z]{2,4}(?:\/)?)$/.test(value);
            }, 'Please enter a valid domain url');


            $.validator.addMethod('selectone', function(value, element) {
                return this.optional(element) || (value.indexOf("none") == -1);
            }, 'Please select an option.');



            $("#form1").validate({
                debug: true,
                rules: {
                    txt_name: {
                        required: true,
                        minlength: 2
                    },
                    txt_cmp: {
                        required: true,
                        minlength: 2
                    },
                    txt_tel1: {
                        phone: true,
                        required: true,
                        minlength: 3

                    },
                    txt_tel2: {
                        phone: true,
                        required: false,
                        minlength: 3

                    },
                    txt_mob: {
                        phone: true,
                        required: false,
                        minlength: 9

                    },
                    txt_email: {
                        required: true,
                        email: true
                    },

                    txt_domname: {
                        required: true,
                        domainurl: true
                    },

                    radiobt_domain: "required",

                    ddl_yremail: {
                        required: true,
                        selectone: true
                    },
                    ddl_email: {
                        required: true,
                        selectone: true
                    },

                    txt_space: {
                        required: true,
                        numbers: true

                    },
                    txt_calfr: {
                        required: true
                    },
                    txt_calto: {
                        required: true
                    }  


            },
            messages: {
                txt_name: {
                    required: "This field is required",
                    minLength: "Please enter a valid name"
                },
                txt_cmp: {
                    required: "This field is required",
                    minLength: "Please enter a valid commpany name"
                },
                txt_tel1: {
                    required: "This field is required",
                    minLength: "Please enter a valid telephone number"

                },
                txt_tel2: {
                    minLength: "Please enter a valid telephone number"
                },
                txt_mob: {
                    minLength: "Please enter a valid mobile number"

                },
                txt_email: {
                    email: "Please enter a valid email address",
                    required: "This field is required"
                },

                txt_domname: {
                    required: "This field is required"
                },
                radiobt_domain: "Select the Hosting Type"
            }

        });
    });
    </script>

代码有什么问题吗?

它在第 559 行显示预期对象。我检查了 jquery.validate.js 文件,这是它显示的代码:

addWrapper: function(toToggle) {
            if ( this.settings.wrapper )
                toToggle = toToggle.add( toToggle.parents( this.settings.wrapper ) );
            return toToggle;
        }

jquery 代码在正确的位置显示所有错误,但一旦更正,它就不会提交数据。

我正在使用的插件:

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

4

6 回答 6

8

当您尝试访问未定义、未引用或错误拼写的对象时,会出现预期的对象。查看预期的对象。使用 Firefox firebug 调试您的 javascript 或使用 IE 进行调试以获取运行时无法找到的对象....

于 2009-05-04T12:05:39.577 回答
2

我通过正确引用 JQuery 文件解决了这个问题。我把它放在一个子目录中,但路径不正确。

于 2011-02-24T05:48:32.877 回答
1

在这里回答:提交按钮不会触发服务器端代码

“调试”应设置为假。

于 2009-05-06T10:55:00.777 回答
0

我的猜测是错误在于您使用 jQuery 验证插件。尝试仅验证一个 ASP.NET 控件。这将使错误更容易被发现:

$("#form1").validate({
    rules: {
       id_of_control_you_know_exists_in_the_rendered_html: {
            required: true,
            minlength: 2
        }
    }
});

另一种可能是您在用户控件中使用 ASP.NET 控件。在这种情况下,呈现的 HTML 输入控件的 id 属性与您在 .aspx 页面中设置的不同。

于 2009-05-05T21:26:51.997 回答
0

我有同样的问题,但在我们的登台服务器上。比较文件表明它们是相同的,并且在不同站点上托管完全相同的文件没有问题,因此它必须是我们放置文件的特定站点。故障排除后的罪魁祸首是我们在 IIS 的网站属性中设置了 Footer.html 文件设置,因此服务器在渲染时将其注入脚本中。因此破坏任何良好的合规代码。我们关闭了 IIS 设置的页脚属性 - 宾果游戏!

于 2009-12-10T18:48:09.217 回答
0

我也面临这个问题。但就我而言,我是 jquery 版本的问题。我放了最新版本,它在 IE 中工作得更好。

于 2010-07-26T07:59:23.177 回答