已经没有足够接近的东西了……至少我的新手头脑可以理解。
我只是想尝试创建一个具有方法的全局包含对象,其中包含创建和使用 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);