1

jqueryが原因で奇妙な理由で「オブジェクトが必要です」というエラーが表示されますが、これはフォームを「送信」したり、データベースにデータを入力したりしません。

jquery がなくても、データをデータベースに入力できます。しかし今はそうではありません。

主にasp.netコントロールの検証にjqueryを使用しました。


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

ここで答えてください:送信ボタンはサーバー側のコードをトリガーしません

「debug」は false に設定する必要があります。

于 2009-05-06T10:55:00.777 に答える
0

私の推測では、エラーはjQuery検証プラグインの使用にあります。1つのASP.NETコントロールのみを検証してみてください。これにより、エラーを見つけやすくなります。

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

もう1つの可能性は、ユーザーコントロールでASP.NETコントロールを使用している可能性があります。その場合、レンダリングされたHTML入力コントロールのidプロパティは、.aspxページで設定したものとは異なります。

于 2009-05-05T21:26:51.997 に答える
0

同じ問題がありましたが、ステージング サーバーで発生しました。ファイルを比較すると、それらが同じであることが示され、まったく同じファイルを別のサイトでホストしても問題はなかったため、ファイルを配置した特定のサイトである必要がありました. トラブルシューティング後の原因は、IIS の Web サイトのプロパティで Footer.html ファイル設定を設定したため、サーバーがレンダリング時にスクリプト内にそれを挿入していたことです。したがって、適切な準拠コードを壊します。IIS 設定でフッター プロパティをオフにしました - ビンゴ!

于 2009-12-10T18:48:09.217 に答える
0

私もこの問題に直面しています。しかし、私の場合、私はjqueryバージョンの問題がありました。私は最新バージョンを入れて、IEでうまくいきました。

于 2010-07-26T07:59:23.177 に答える