Jump to content

php, ajax, js help


UnknownPlayer

Recommended Posts

I have this form:

    <textarea id="pp" name="post_text" rows="1" cols="50"></textarea><br />
    <input type="submit" value="Post" onClick="postit()" />
    <div id="posted"></div>

this is postit() js code:

<script type="text/javascript">
function postit(){
var post_text = document.getElementById('pp');
if (post_text != "") {
	if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else { // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			document.getElementById("posted").innerHTML=xmlhttp.responseText;
		}
	}
	var data = "content="+post_text;
	xhr.open("POST", "send_post.php", true); 
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
	xhr.send(data);
}
}
</script>

.. and this is send_post.php code:

<?php include("includes/connection.php"); ?>
<?php
$content = $_POST['content'];
$content_date = time();
$query = "INSERT INTO wallposts (post, date) VALUES ('{$content}', '$content_date')";
$result = mysql_query($query);
echo "Posted";
?>

 

Now, js code gets in post_text var, text of "pp" input value, but it wont send it to send_post.php(POST method) and write at mysql :S

Can someone help me? :(

Thanks..

Link to comment
https://forums.phpfreaks.com/topic/228543-php-ajax-js-help/
Share on other sites

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.