'Bootsrap 4.0.0 stable' causes 'Uncaught TypeError: Cannot read property 'apply' of undefined.'

'Bootsrap 4.0.0 stable' causes 'Uncaught TypeError: Cannot read property 'apply' of undefined.'

到目前为止,我一直在使用 Bootstrap 4.0.0-beta2 和插件 jquery-Validate 与 1.17.0 来验证表单数据。 没关系。

现在我转到 'Bootstrap 4.0.0 stable' 并收到以下错误:

jquery.validate.min.js:4 Uncaught TypeError: Cannot read property 'apply' of undefined.  Exception occurred when checking element idUserNameProvRegister, check the 'remote' method.
    at Function.a.ajaxPrefilter.a.ajax (jquery.validate.min.js:4)
    at a.validator.remote (jquery.validate.min.js:4)
    at a.validator.check (jquery.validate.min.js:4)
    at a.validator.element (jquery.validate.min.js:4)
    at a.validator.onfocusout (jquery.validate.min.js:4)
    at HTMLInputElement.b (jquery.validate.min.js:4)
    at HTMLFormElement.dispatch (jquery-3.2.1.slim.min.js:3)
    at HTMLFormElement.q.handle (jquery-3.2.1.slim.min.js:3)
    at Object.trigger (jquery-3.2.1.slim.min.js:3)
    at Object.simulate (jquery-3.2.1.slim.min.js:3)

问题似乎出自 jquery-验证插件所需的这部分代码:

  $("#idFormProvRegister").validate({

        rules:{
          UserNameProvRegister: {
                required:       true,
                length_username: true,
                alphanumeric:   true,

                remote: {   
                    url: "ajax/IstUserNameVergeben.php",
                    type: "post",
                    data: {
                        UserNameProvRegister: function(){
                            return $("#idUserNameProvRegister").val();
                        }
                    }              
                }
          },
  .....

除了这些 cdns(新 Bootstrap 版本需要)外,我没有对自己的代码进行任何更改:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

   <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

在这两种情况下('BS 4.0.0 beta2' 以及 'BS 4.0.0 stable')我使用了相同的 jquery 版本。 有人知道如何解决这个问题吗?

亨利

  1. 一些故障排除是有序的。安装插件的未缩小版本,以便可以将错误消息跟踪到可读的内容。

  2. 错误消息包含,"Exception occurred when checking element idUserNameProvRegister, check the 'remote' method." 所以这应该会缩小范围。

  3. 您安装了一个名为 jQuery "Slim" 的东西。我很确定这不是 jQuery 的完整版本。 (根据 OP 的评论,"slim" 不支持 Ajax)

  4. 最后,remote 中的 data 参数在这种情况下是完全多余的。默认情况下,remote 方法发送正在验证的字段的值,因此无需指定。