【问题标题】:Uncaught TypeError: Cannot read property 'toLowerCase' of undefined on jQuery function未捕获的类型错误:无法读取 jQuery 函数上未定义的属性“toLowerCase”
【发布时间】:2017-07-26 19:57:31
【问题描述】:

我在一个页面中有这个 jQuery 脚本

$(document).ready(function() {
  $.ajax({
    type: "POST",
    url: "/notification/unread",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data){
      $("#notification_badge").html(data).removeClass("hidden");
    }
  });

但是,在调用 $.ajax 函数时,我遇到了一个错误:

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined on jQuery function

这是我在控制台中找到的

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
    at Object.setRequestHeader (jquery.min.js:4)
    at HTMLDocument.<anonymous> (badge.js:5)
    at HTMLDocument.dispatch (jquery.min.js:3)
    at HTMLDocument.r.handle (jquery.min.js:3)
    at Object.trigger (jquery.min.js:3)
    at Function.ajax (jquery.min.js:4)
    at badge.js:10
    at dispatch (jquery.min.js:3)
    at r.handle (jquery.min.js:3)

未进行 POST 调用。哪里出错了?

【问题讨论】:

  • 您是否在 POST 请求中添加了任何 data
  • 编辑完全错误,ajax 调用永远不会...
  • @RoryMcCrossan 没有数据
  • 你没有给它任何与 Rory 的问题相关的数据。

标签: jquery ajax


【解决方案1】:

尝试将函数定义更改为 ES6 标准。从此

$(document).ready(function() {});

到这里

$(document).ready(() =>{});

【讨论】:

  • 请描述这是如何回答问题的。对我来说,这看起来像是一个旁注,因为问题是关于 toLowerCase
  • 你试过了还是不行?我遇到了类似的情况,以上为我解决了。
猜你喜欢
  • 2014-07-06
  • 2016-03-25
  • 2018-05-16
  • 1970-01-01
  • 2021-10-13
  • 2020-11-17
  • 2017-06-26
  • 2017-08-23
相关资源
最近更新 更多