jquery.js文件版本3.6在按钮单击时抛出错误

j1dl9f46  于 5个月前  发布在  jQuery
关注(0)|答案(2)|浏览(73)

我有一个应用程序,它使用jQuery的客户端。它一直工作正常,但我已经开始得到一个错误的jQuery文件,即使没有改变的代码。
这就是按钮代码:

<a id="lookup" href="#SummaryModal" type="button" data-toggle="modal" data-backdrop="static" class="btn btn-tertiary" title="Summary"><span class="glyphicon glyphicon-list" aria-hidden="true"></span>Quick Summary</a>

字符串
这是脚本代码,但下面的错误甚至在控件到达此代码之前就被抛出了。

$(document).on("click", "#lookup", function (e) {
        $.ajax({
            url: "/Home/GetSummary/",
            type: 'POST',                
            beforeSend: function (xhr) {
                xhr.setRequestHeader("XSRF-TOKEN",
                    $('input:hidden[name="__RequestVerificationToken"]').val());
            },
            cache: true,
            async: true

        }).done(function (result) {
            $("#divSummary").html(result);
        });
    })


在点击它时,我得到以下错误:
无法读取未定义的属性(阅读“jQuery 360059256788808060092”)
at Data.get(jquery.js:4301:9)
at Data.access(jquery.js:4319:16)
在Function.data(jquery.js:4459:19)
at HTMLAnchorElement.delegate(jquery.validate.js:419:23)
at HTMLFormElement.dispatch(jquery.js:5430:27)
at elemData.handle(jquery.js:5234:28)
at Object.trigger(jquery.js:8719:12)
at Object.simulate(jquery.js:8788:16)
at HTMLDocument.handler(jquery.js:8822:17)
js:4301
access @ jquery.js:4319
data @ jquery.js:4459
delegate @ jquery.validate.js:419
jquery.js:5430
elemData.handle @ jquery.js:5234
trigger @ jquery.js:8719
simulate @ jquery.js:8788
邮箱:jquery @ jquery.js
我已经附上了相同的屏幕截图。我试图更新jquery文件,看看它是否与jquery版本有关,但它仍然抛出相同的错误。我已经检查了jqueryvalidate1.17与jquery3.6的兼容性,似乎没有问题。
有没有什么线索能帮我修好它?
图片来源:https://imgur.com/a/LcRdwD5

bvpmtnay

bvpmtnay1#

我建议你检查consol.log这两个变量:$('input:hidden[name="__RequestVerificationToken"]').val()result .如果其中一个是未定义的,你知道为什么你得到这个错误的原因.这里是这个错误代码的解释:
TypeError的原因:无法读取未定义的属性错误明确指出它是未定义的,这意味着变量可能被声明或使用。但是,没有与变量关联的值。简而言之,值没有被赋值。
在JavaScript中,属性或函数是Object,但undefined不是对象类型。如果调用此类变量的函数或属性,则会在控制台TypeError中获得错误:无法读取未定义的属性。

kpbwa7wx

kpbwa7wx2#

我知道这是一个奇怪的修复,我没有解释为什么这是工程,但我有几个其他链接的类型按钮,这是工作正常。所以唯一的区别,这一个和其他链接是prescence的类型= '按钮'代码。
下面的代码:

<a id="lookup" href="#SummaryModal" type="button" data-toggle="modal" data-backdrop="static" class="btn btn-tertiary" title="Summary"><span class="glyphicon glyphicon-list" aria-hidden="true"></span>Quick Summary</a>

字符串
成为

<a id="lookup" href="#SummaryModal" data-toggle="modal" data-backdrop="static" class="btn btn-tertiary" title="Summary"><span class="glyphicon glyphicon-list" aria-hidden="true"></span>Quick Summary</a>


瞧,它工作了。与jquery版本或jquery文件无关。

相关问题