PDA

View Full Version : JSON Ajax Chat Script


ptmuldoon
01-14-2008, 11:11 PM
Is anyone familar with the JSON Ajax chat script? It appears be very lightweight and what I am possibly looking for. But I'm unsure how you would alter the script to include a sites username, instead of the hard coded Name included in the script.

The script can be found Here (http://www.dynamicajax.com/fr/JSON_AJAX_Web_Chat-271_290_324.html)

and the script includes the following:

//Add a message to the chat server.
function sendChatText() {
if(document.getElementById('txt_message').value == '') {
alert("You have not entered a message");
return;
}
if (sendReq.readyState == 4 || sendReq.readyState == 0) {
sendReq.open("POST", 'getChat.php?chat=1&last=' + lastMessage, true);
sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
sendReq.onreadystatechange = handleSendChat;
var param = 'message=' + document.getElementById('txt_message').value;
param += '&name=Ryan Smith';
param += '&chat=1';
sendReq.send(param);
document.getElementById('txt_message').value = '';
}
}

you can see the name is hard coded to a Ryan Smith. I like to change that to something to use a php variable that is represents the user's session name.

shyam
01-15-2008, 05:46 AM
var param = 'message=' + document.getElementById('txt_message').value;
param += '&name=<?php echo $_SESSION['username'] ?>';
param += '&chat=1';

or, are u looking for something more complicated?