2009-05-04 8 views
1

jqueryのために何らかの理由で 'Object expected'エラーが発生しました。これはフォームを 'submit'したり、データをデータベースに入力しません。オブジェクトが期待されています - jquery

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

私は主にasp.netコントロールの検証にjqueryを使用しています。


ロスステロン酸では、検証は完全にうまく機能しており、idプロパティも同じです。送信は、サーバー側のコードを実行していないと私は問題が何であるか把握することはできません。

EDIT:

これは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> 

は、コードに何か問題はありますか?

それは私がjquery.validate.jsファイルをチェックし、これはそれが示したコードであるオブジェクトは、ライン559で期待言う:

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/

+2

いくつかのコードをご覧ください。私たちがそれを見ることができなければ何が壊れているのかを教えてもらえません。 –

+8

jQueryがデータベースを更新していないときに嫌い:/ –

+0

コードスニペットなしjQueryの前に、jQueryが修正された壊れたIEの動作に依存するIE専用のコードがあると推測できます。例えばあなたが$( '#myFormID')をやろうとした場合。 on

...
以前のJSはdocument.all.myFormID.submit()でした。または類似。 – scunliffe

答えて

8

オブジェクトが発生しました。どのオブジェクトが期待されているか確認してください。 Firefoxのfirebugを使用してJavaScriptをデバッグするか、IEでデバッグして、ランタイムが見つからないオブジェクトを取得します。

0

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

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

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

0

私は同じ問題を抱えていましたが、私たちのステージングサーバーではありました。ファイルを比較すると、ファイルが同じであることが示され、別のサイトでまったく同じファイルをホストすることに問題はなく、ファイルを置く特定のサイトでなければなりませんでした。トラブルシューティング後の犯人はIISのWebサイトのプロパティにFooter.htmlファイル設定を設定していたため、サーバーはレンダリング時にスクリプト内にそのファイルを挿入していました。したがって、適切な適合コードを破棄してください。 IIS設定のフッタープロパティ - bingo!をオフにしました。

0

私もこの問題に直面しています。しかし、私の場合、私はjqueryバージョンprobだったです。私は最新のバージョンを入れ、それはIEでgreateしています。

2

JQueryファイルを正しく参照することでこの問題を解決しました。私はサブディレクトリにそれを持っていて、正しいパスを持っていませんでした。

関連する問題