Jump to content

Need help with a chat room script


fert

Recommended Posts

I've just started Ajax and this is some code I came up with for a chat room
Here's my code
[code]
function makerequest()
{
var request;
if (window.XMLHttpRequest)
{
        request = new XMLHttpRequest();
}
else
if (window.ActiveXObject)  // ActiveX version
{
      request = new ActiveXObject("Microsoft.XMLHTTP");
}

request.onreadystatechange = function()
if(request.readyState == 4)
  {
      if(request.status == 200)
          document.chat.text.value="Received:" + req.responseText;
      else
          document.chat.text.value="Error code " + req.status;
  }
  req.open(POST,"chat.php",true);
  req.send("?text="+encode(document.chat.new_text.value)+"&user="+encode(document.chat.username.value));
}

function update()
{
var request;
if (window.XMLHttpRequest)
{
        request = new XMLHttpRequest();
}
else
if (window.ActiveXObject)  // ActiveX version
{
      request = new ActiveXObject("Microsoft.XMLHTTP");
}

request.onreadystatechange = function()
if(request.readyState == 4)
  {
      if(request.status == 200)
          document.chat.text.value=" + req.responseText;
      else
          document.chat.text.value="Error code " + req.status;
  }
  req.open(GET,"chat.php",true);
  req.send(null);
}
[/code]
The code isn't updating the database (which is what chat.php does). can anybody tell me why?
Link to comment
Share on other sites

when you POST from ajax to a php script, your SEND content do not got populated into $_POST.  check this out to make sure.
Instead, it ended up in $_GLOBALS['HTTP_RAW_POST_DATA']
something like that, I'm not so sure about the name, but you should do some echo and check.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.