【问题标题】:Uncaught TypeError: Illegal invocation (chrome)未捕获的 TypeError:非法调用(chrome)
【发布时间】:2013-07-31 14:49:40
【问题描述】:

当用户单击按钮 (onclick="Website.submit()") 时,我试图在 JavaScript 中调用一个函数,但我的代码不起作用。

我在 Chrome 中收到此错误:

未捕获的类型错误:非法调用

在 Chrome 中,此行在 jquery.js 中被突出显示为错误来源:

// If value is a function, invoke it and return its value

value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );

开发者面板的控制台选项卡 (F12) 上的更详细错误:

代码如下:

var Website = {

  submit: function () {

    var stap1 = $('#stap1').val();
    var stap2 = $('#stap2').val();
    var stap3 = $('#stap3').val();
    var letop = $('#letop').val();

    if (stap1.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#stap1').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (stap2.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#stap2').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (stap3.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#stap3').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (letop.length == 0) {
      $('#error2').show();
      $('#the_error2').html('Je moet alle velden invullen om door te gaan.');

      $('#letop').css({
        'border-width': '1px',
        'border-color': 'red'
      });
    }

    if (stap1.length !== 0 && stap2.length !== 0 && stap3.length !== 0 && letop.length !== 0) {

      $.post(General.url + "/pages/website_check.php", {
        naam: naam,
        subdomein: subdomein,
        stap1: stap1,
        stap2: stap2,
        stap3: stap3,
        letop: letop
      }, function (result) {

        if (result == 1) {
          $('#error2').show();
          $('#the_error2').html('Deze naam is al in gebruik. Ga snel terug en kies een andere.');

          $('#error').show();
          $('#the_error').html('Deze naam is al in gebruik. Kies een andere.');

          $('#naam').css({
            'border-width': '1px',
            'border-color': 'red'
          });

        } else {
          if (result == 2) {
            $('#error2').show();
            $('#the_error2').html('Dit subdomein is al in gebruik. Ga snel terug en kies een andere.');

            $('#error').show();
            $('#the_error').html('Dit subdomein is al in gebruik. Kies een andere.');

            $('#subdomein').css({
              'border-width': '1px',
              'border-color': 'red'
            });
          }
        }
      });
    }
  }

};

【问题讨论】:

  • 您是否发布到与加载脚本不同的域?
  • 不,它是相同的 General.url 给了我自己的本地主机。
  • general.js 的第 128 行及其周围有什么?
  • 我想问和 Alex Wayne 一样的问题。看起来问题的根源在于$.post() 方法,但我们应该知道更多细节。您还应该调试General.url 是否不在范围内,以及它是否具有此处可接受的有效值(例如,字符串,它不是对象)。 naamsubdomein 变量也应该被调试。

标签: javascript jquery


【解决方案1】:

只需注释该行 值 = jQuery.isFunction(值)?价值():(价值==空?“”:价值); 在 jQuery.js 中。

add = function( key, value ) {
        // If value is a function, invoke it and return its value
        //value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
        s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
    };

【讨论】:

    猜你喜欢
    • 2012-03-29
    • 1970-01-01
    • 2016-12-07
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 2018-08-28
    • 1970-01-01
    相关资源
    最近更新 更多