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

 

Link to comment
Share on other sites

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

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.