Jump to content

[SOLVED] Send post vars


DeanWhitehouse

Recommended Posts

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

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...?

 

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 :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.