gpt4 book ai didi

javascript - 令人困惑的类型错误 : Cannot read property 'n' of undefined

转载 作者:行者123 更新时间:2023-11-30 06:05:22 28 4
gpt4 key购买 nike

在试图在字典中传递两个值的 ajax 调用(用于游戏)中,似乎只有一个值被读入,而另一个(JavaScript 类的实例)似乎正在抛出“TypeError:无法读取未定义的属性“col”。尽管事实上此调用的构建方式与使用相同代码且运行良好的其他调用完全相同。

这是导致问题的类:

function Cell(col, row) {
this.col = col;
this.row = row;
// as well as an .eq and .ne and one or two other simple methods
}

这是调用的设置:

uCell = new Cell(-1, -1); // creates the Cell instance to pass
var dataout = {
ucell:uCell,
boardnumber:G.BOARDNUM,
};
// able to alert out both ucell and uCell values here just fine as well as boardnumber

这是调用本身:

rqst_cellboard = $.ajax({
type: "POST",
data: dataout,
url: "/project03/cellboardcall/", // this never gets called
dataType:"json",
error: // etc.
success: // etc.

在进行 ajax 调用之前抛出错误,显然是在设置它时。在抛出错误的 jQuery 断点处查看 context 对象,看起来 data 值中只有 boardnumber,而不是 ucell。错误显示为 TypeError: Cannot read property 'col' of undefined。我不知道在 jQuery 中的什么地方可以找到未定义的参数,但我假设它是 ucell,因为它应该具有 col 属性。

进入通话时一切似乎都定义得很好,但通话本身却变得乏味。我敢肯定这很简单,但我想不通。感谢任何想法。

最佳答案

rqst_cellboard = $.ajax({
type: "POST",
data: dataout,
url: "/project03/cellboardcall/", // this never gets called
dataType:"json",
error: // etc.
success: // etc.

我敢打赌这个问题与“dataout”不是格式正确的 JSON 对象这一事实有关。特别是,它引用了 uCell,它本身不是 JSON 对象,因为您说它实现了方法。

JSON 对象必须遵循一组相当严格的规则,就它们可以拥有的属性种类而言。您可能需要仅为 ajax 调用创建一个新对象,该对象仅包含您实际要传输的属性。

关于javascript - 令人困惑的类型错误 : Cannot read property 'n' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5312856/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com