DeanWhitehouse Posted August 12, 2008 Share Posted August 12, 2008 How do i send post vars using ajax, this is my code function addmessage() { var xmlhttp=createhandler(); xmlhttp.onreadystatechange=function (){ if(xmlhttp.readyState==4) { xmlhttp.onreadystatechange = null; xmlhttp.abort(); } }; xmlhttp.open('POST', 'postchat.php', true); xmlhttp.send(null); return true; } function createmessage() { var button = document.getElementById('post'); if(validatechat()) { if(addmessage()) { button.value='Message Posted'; button.disabled=true; if(shouts()) { return true; } } return false; } return false; } and my php code <form action="javascript:void(0)" onSubmit="return createmessage();" method="post"> <input type="text" id="name" name="name" size="25"><br> Your Message<br> <textarea rows="5" cols="19" id="message"></textarea><br> <input type="submit" value="Post Message" name="postmessage" id="post"> </form> and this is my insert code <?php $db = mysql_connect("host","uname","pword"); $dbsel = mysql_select_db("dbname"); $name = $_POST['name']; mysql_query("INSERT INTO `spearbang_shoutbox` (`id`,`name`,`message`,`ip`,`time`)VALUES ('','$name','test','test','test');") ; ?> But this doesnt insert a name , any help? Link to comment https://forums.phpfreaks.com/topic/119383-solved-send-post-vars/ Share on other sites More sharing options...
DeanWhitehouse Posted August 12, 2008 Author Share Posted August 12, 2008 Might help if i say what it's for , i would of edited but i am 2late. It will be an ajax shoutbox, bit like a chat box Link to comment https://forums.phpfreaks.com/topic/119383-solved-send-post-vars/#findComment-615034 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 var params = 'foo=bar&name=darkwater'; xmlhttp.open('POST', 'postchat.php', true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); return true; Did you even try Googling by the way? I knew how to do this, but then I googled it just to prove a point, and there are a TON of results. =/ And why'd you post this in the wrong board...? Link to comment https://forums.phpfreaks.com/topic/119383-solved-send-post-vars/#findComment-615060 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 Ok thanks for that , i don't get what the params are for though, and what they are. but i will test with this , also i didnt try googling ,i like to keep you on ure toes lolz , i will google first next time , and also i posted here because , half the time i never get a reply in the other rooms and because everyone posts JS questions here and doesnt moan so i thought i would Link to comment https://forums.phpfreaks.com/topic/119383-solved-send-post-vars/#findComment-615167 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 DW u reported it? Link to comment https://forums.phpfreaks.com/topic/119383-solved-send-post-vars/#findComment-615182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.