IE8上的jQuery验证错误

时间:2014-10-10 11:50:57

标签: jquery validation internet-explorer-8

我得到一个'对象并不支持这种方法或属性' IE8上的错误。它所指的代码行如下:

 $('#example-advanced-form').ajaxForm({
      target: '.success',
      success: function() {
          $('.success').fadeIn('fast');
          $("#contact_form").toggle("fast");
      }
});

我使用它的原因是因为FormData在IE10下无效。

以下是错误的屏幕截图:

enter image description here

这是完整的脚本......

        <script type="text/javascript">    

        var form = $("#example-advanced-form").show();


          $('#role').validate({ // initialize the plugin
              rules: {
                  role: {
                      required: true,
                  }
              }
          });

        form.steps({
            headerTag: "h3",
            bodyTag: "fieldset",
            transitionEffect: "slideLeft",

            onStepChanging: function (event, currentIndex, newIndex)
            {
                // Allways allow previous action even if the current form is not valid!
                if (currentIndex > newIndex)
                {
                    return true;
                }


                // Needed in some cases if the user went back (clean up)
                if (currentIndex < newIndex)
                {
                    // To remove error styles
                    form.find(".body:eq(" + newIndex + ") label.error").remove();
                    form.find(".body:eq(" + newIndex + ") .error").removeClass("error");
                }
                form.validate().settings.ignore = ":disabled,:hidden";
                return form.valid();
            },

            onStepChanged: function (event, currentIndex, priorIndex)
            {
                // 
                if (currentIndex === 2 && $("input:radio[name='workfor']").is(":checked"))
                {
                    form.steps("next");
                }

            },

            onFinishing: function (event, currentIndex)
            {
                form.validate().settings.ignore = ":disabled";
                return form.valid();
            },

            onFinished: function (event, currentIndex)
            {



              if(navigator.appVersion.indexOf("MSIE 8.")!=-1 || navigator.appVersion.indexOf("MSIE 9.")!=-1) {

                  //alert("old IE!");

                  // bind 'myForm' and provide a simple callback function 



                $('#example-advanced-form').ajaxForm({
                  target: '.success',
                  success: function() {
                  $('.success').fadeIn('fast');
                  $("#contact_form").toggle("fast");
                  }
                });


              } else {
                 //alert("Not old IE!");



              //data to be sent to server         
              var m_data = new FormData();    
              m_data.append( 'name', $('input[name=name]').val());
              m_data.append( 'number', $('input[name=number]').val());
              m_data.append( 'email', $('input[name=email]').val());
              m_data.append( 'workfor', $('input[name=workfor]:checked').val());
              m_data.append( 'role', $('select[name=role]').val());
              m_data.append( 'cv', $('input[name=cv]')[0].files[0]);
              m_data.append( 'coverletter', $('textarea#coverletter').val());



              //instead of $.post() we are using $.ajax()
              //that's because $.ajax() has more options and flexibly.
              $.ajax({
                url: 'contact_me.php',
                data: m_data,
                processData: false,
                contentType: false,
                type: 'POST',
                dataType:'json',
                success: function(response){
                   //load json data from server and output message     
                  if(response.type == 'error'){ //load json data from server and output message     
                      output = '<div class="error">'+response.text+'</div>';
                  }else{
                      output = '<div class="success">'+response.text+'</div>';
                      $("#contact_form").toggle("fast");
                  }
                  $(".form_message").hide().html(output).slideDown();
                }
              });  

            }//END browser check coniditonal statement


            }

        }).validate();


        </script>

1 个答案:

答案 0 :(得分:1)

$.ajaxForm不是JQuery的标准方法;最有可能的是,引用此附加组件的脚本失败,或者顺序错误。如果失败,则可能是脚本文件的名称或位置错误,或者页面或该插件中发生错误,导致错误。使用调试工具将有助于识别问题(IE的开发人员工具包,带有firebug的firefox,带有它的chrome&dev工具或firebug)。