UPDATE^^
Also hab jetzt die erstellung des Object in onload reingepackt. Aber die getElementById-Sachen sind immer noch null.(also content_div und so)
Ich hab ja die Variablen in ner Funktion definiert, aber die sind ja global wegen dem var, oder?
Also neuer Source:
JavaScript
function WholemealShout()
{
this.init = function(shoutbox_content_id, shoutbox_input_form_id, shoutbox_bmsg_id){
var content_div = document.getElementById(shoutbox_content_id);
alert(shoutbox_content_id);
alert(content_div);
var input_form = document.getElementById(shoutbox_input_form_id);
var bot_span = document.getElementById(shoutbox_bmsg_id);
var req = null;
this.autorefresh = null;
}
this.getXmlHttpRequest = function(){
if (window.XMLHttpRequest)
{
httpReq = new XMLHttpRequest();
} else if (typeof ActiveXObject != "undefined")
{
httpReq = ActiveXObject("Microsoft.XMLHTTP");
}
return httpReq;
}
this.show = function(all){
all = all || 0;
req = this.getXmlHttpRequest();
req.onreadystatechange = this.response_chat_xml;
if(all==0){
req.open("GET", "WholemealShout.php?all=0", true);
} else if(all == 1){
req.open("GET", "WholemealShout.php?all=1", true);
}
req.send(null);
return null;
}
this.response_chat_xml = function(){
if(req.readyState == 4){
xml = req.responseXML;
msg_length = xml.getElementsByTagName("msg").length;
content = "";
i = 0;
alert("lol");
while(i<msg_length){
content += "<p>"+xml.getElementsByTagName("msg")[i].firstChild.data+"</p>";
i++;
}
alert("xD");
alert(content_div);
content_div.innerHTML += content;
alert("xD");
if(xml.getElementsByTagName("aref") != null){
button = "<input type=\"button\" onclick=\"show()\" name=\"chat_act\" id=\"chat_act\" value=\"Aktualisieren\">";
input_form.innerHTML += button;
}
if(xml.getElementsByTagName("bmsg") != null){
bot = xml.getElementsByTagName("bmsg").firstChild.data;
bot_span.innerHTML += bot;
}
req = null;
}
if(this.autorefresh == true){
setInterval(this.show, 300);
}
return null;
}
}
wholemeal = new WholemealShout();
function init_wholemeal(){
wholemeal.init("shoutbox_content ", "shoutbox_input_form", "shoutbox_bmsg");
wholemeal.show(1)
}
window.onload = init_wholemeal();
Alles anzeigen