在試圖在字典中傳遞兩個值的ajax調用(對於遊戲)中,只有一個值似乎正在讀入,而另一個值JavaScript類的實例)似乎在拋出「TypeError:無法讀取未定義的屬性'col'。」儘管這個調用與其他調用完全相同,但是在相同代碼中可以正常工作。混淆TypeError:無法讀取未定義的屬性'n'
這裏的,這似乎是導致問題的類:
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
屬性。
一切似乎都很好地進入呼叫定義,但呼叫本身越來越borked。我相信這是非常簡單的,但我無法想象它。感謝任何想法。
您的問題中共享的代碼沒有問題。檢查是否覆蓋「uCell」。 – 2011-03-15 14:27:24