Forum Moderators: coopster

Message Too Old, No Replies

Undefined Index problem

Part of an AJAX chatroom for SMF forum

         

TrueSatan

1:20 am on Mar 2, 2007 (gmt 0)

10+ Year Member



The code I'm trying to fix is as follows:

 function autoRefresh(){
var myAjax = new Ajax.Request( \'Sources/tpvchat/func/chat.php\', {method: \'post\', parameters: "act=clientIn&guestname='.$_SESSION['chatsession'].'", onComplete: function(res){
ob=JSON(res)
if (ob.error){alert(ob.errors)}
}});
new Ajax.PeriodicalUpdater("content",\'Sources/tpvchat/func/chat.php\' , {asynchronous:true, frequency:1, method: \'post\', parameters: "act=get"});

}
function doRefresh(){
new Ajax.Updater("content",\'Sources/tpvchat/func/chat.php\' , {method: \'post\', parameters: "act=get"});
}
function PostMessage(form) {
var myAjax = new Ajax.Request( \'Sources/tpvchat/func/chat.php\', {method: \'post\', parameters: "act=post&"+Form.serialize(form), onComplete: function(res){
ob=JSON(res)
if (ob.error){alert(ob.errors)}
}});
setTimeout("doRefresh()",1);
el=document.getElementById("Tmessage")
el.focus();
setTimeout(\'el.value=""\',3);
el.value="";
}
function ClearChat(form) {
var myAjax = new Ajax.Request( \'Sources/tpvchat/func/chat.php\', {method: \'post\', parameters: "act=clearchat", onComplete: function(res){
ob=JSON(res)
if (ob.error){alert(ob.errors)}
}});
setTimeout("doRefresh()",1);
}
function delPost(id) {
var myAjax = new Ajax.Request( \'Sources/tpvchat/func/chat.php\', {method: \'post\', parameters: "act=del&id="+id , onComplete: function(res){
ob=JSON(res)
if (ob.error){alert(ob.errors)}
}});
setTimeout("doRefresh()",1);
}
_handleKey=function(ob,e){
e.Key=(e.keyCode)?e.keyCode:e.which;
if (e.Key==13){
if (e.shiftKey){
return true;
}else{
PostMessage(ob.form);
try{
ob.preventDefault();
}catch(e){
ob.returnValue=false;
}
ob.value=""
return false;
}
}
}
function leaveChat(){
var myAjax = new Ajax.Request( \'Sources/tpvchat/func/chat.php\', {asynchronous:false,method: \'post\', parameters: "act=clientOut&guestname='.$_SESSION['chatsession'].'", onComplete: function(res){
ob=JSON(res)
if (ob.error){alert(ob.errors)}
}});
}
</script>';
}

The code gives 2 errors...Undefined index: chatsession

Would anyone be so kind as to offer a solution?

grandpa

1:37 am on Mar 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi TrueSatan, and welcome to WebmasterWorld

At first glance it looks like you are passing chatsession back to chat.php, along with other parameters. One possibility is that you are using a GET in chat.php, but you are POST'ing the values from this script. If that's the problem, the solution is to read your POST variables in chat.php

$x = $_POST['abc'];

TrueSatan

6:30 pm on Mar 2, 2007 (gmt 0)

10+ Year Member



Thanks Grandpa...and for your welcome. I managed to figure it out with your tip as a guide.