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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
fert Posted January 23, 2007 Author Share Posted January 23, 2007 thanks now it works Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.