這已經不夠接近這個了......至少我的新手頭腦可以把握。在控制檯中導致未定義錯誤的對象
我只是試圖創造一個全球包含對象具有方法,幷包含在內的是創建和使用AJAX請求的說明。然後我繼續爲一個按鈕創建一個事件監聽器。然後我得到以下控制檯輸出。
Port: Could not establish connection. Receiving end does not exist. -This was deleted-.net/:1
Uncaught ReferenceError: globOject is not defined script.js:21
Port: Could not establish connection. Receiving end does not exist. -This was deleted-.net/:1
Exception in onResRdy: TypeError: Cannot read property 'htmlRes' of undefined ContentScript.js:84
我確定我在這裏犯了很多錯誤。讓我知道我需要包括什麼額外的信息來獲得這方面的援助。
var globObject = {
sendToServer: function() {
alert('you got to me at least!');
var xhr;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xhr=new XMLHttpRequest();
}
else {// code for IE6, IE5
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open('POST', 'counterDoc.php', true);
xhr.send();
},
counterClick: function (counter) {
alert('you got here!');
counter += 1;
this.sendToServer();
}};
var button = document.getElementById('submbut').addEventListener('click',globOject.counterClick(0), true);
錯字:'globOject.counterClick(0),TRUE);'應該是'globObject.counterClick(0),TRUE);' – lastr2d2
這個問題似乎是題外話,因爲它只是一個錯字。 – Barmar
對不起,我錯過了那些傢伙,我現在很難過。 :( –