Hello.
My shoutbox I have made seems to say "undefined" at the start of it.
This is my javascript code.
And this is the JSON code,
The code it puts into the the div (shouts_box.innerHTML)
Thanks 4 ya help
My shoutbox I have made seems to say "undefined" at the start of it.
This is my javascript code.
| Code: |
| function getshouts() {
var shouts_box = document.getElementById('shouts'); var shoutbox_text; jsongetshouts=GetXmlHttpObject() if(jsongetshouts) { jsongetshouts.open("POST", "<?=$siteurl?>ajax/shoutbox.php"); jsongetshouts.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); jsongetshouts.onreadystatechange = function () { if (jsongetshouts.readyState == 4) { if (jsongetshouts.status == 200 || jsongetshouts.status == 0) { var response = eval("(" + jsongetshouts.responseText + ")"); for(i=0;i < response.shoutbox.message.length; i++) { if (i%2) { rocolor = "2"; } else { rocolor = ""; } shoutbox_text += "<div class=\"conbgnb"+rocolor+"\">"; shoutbox_text += "<strong><a href=\"<?=$siteurl?>profile/"+response.shoutbox.message[i].poster+"/\" class=\"tutoriallink\">"+response.shoutbox.message[i].poster+":</a></strong><br />"; shoutbox_text += response.shoutbox.message[i].msgtext; shoutbox_text += "</div>"; } shouts_box.innerHTML = shoutbox_text; } } }; jsongetshouts.send("key=<?=$ajaxkey?>"); } } |
And this is the JSON code,
| Code: |
| {"shoutbox":
{"message":[ {"msgid": "2", "poster": "You", "msgtext": "hello me" },{"msgid": "1", "poster": "Me", "msgtext": "hello you" } ] } } |
The code it puts into the the div (shouts_box.innerHTML)
| Quote: |
| undefined<div class="conbgnb"><strong><a href="profile/DanielXP/" class="tutoriallink">DanielXP:</a></strong><br />same again |
Thanks 4 ya help
