fert Posted January 21, 2007 Share Posted January 21, 2007 I've just started Ajax and this is some code I came up with for a chat roomHere'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 https://forums.phpfreaks.com/topic/35039-need-help-with-a-chat-room-script/ Share on other sites More sharing options...
hvle Posted January 23, 2007 Share Posted January 23, 2007 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 https://forums.phpfreaks.com/topic/35039-need-help-with-a-chat-room-script/#findComment-166830 Share on other sites More sharing options...
fert Posted January 23, 2007 Author Share Posted January 23, 2007 thanks now it works Link to comment https://forums.phpfreaks.com/topic/35039-need-help-with-a-chat-room-script/#findComment-166862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.