Actually I am working on a chatbox....But It doesn't meet this condition. Here is the code
function submitChat() {
if (form1.users.value == "" || form1.messege.value == "") {
alert("Please fill the all feild");
return;
}
var users = form1.users.value;
var messege = form1.messege.value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
//Here is the problem may be
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementByID('shouts').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', 'process.php?users' + users + '&messege' + messege, 'true');
xmlhttp.send();
Here these variable shows undefined..
$users = $_REQUEST['users'];
$messege = $_REQUEST['messege'];
You've left out the =
between the parameter names and their values.
Also, when you're sending a URL parameter that could include special characters, you need to encode it properly, using encodeURIComponent()
xmlhttp.open('GET', 'process.php?users=' + encodeURIComponent(users) + '&messege=' + encodeURIComponent(messege), true);
Note also that the third argument should be a boolean, not a string (although since any non-empty string is truthy, 'true'
will have the same effect as true
, but 'false'
would not be equivalent to false
).
It's also not usually a good idea to use a URL parameter for long inputs like messages, you should use POST
data instead.
xmlhttp.open('POST', 'process.php', true);
xmlhttp.send('users=' + encodeURIComponent(users) + '&messege=' + encodeURIComponent(messege));