I have a problem in posting form elements through ajax, what am i doing wrong? Can anyone help me please :(

<?php
error_reporting(5);

$uid = "username";
$tid = 500;
$photoTiding = "true";
$picName = "picname";
$pid = "pid";
include('sample_db.php');
//displaying users pic and textarea to comment.
$user = "SELECT pic FROM user WHERE userid='$uid'";
$resultUser = mysql_query($user,$con);
$rowUser = mysql_fetch_array($resultUser);

//including addtidingcomment_ajaxx script.
//include("Scripts/addtidingcomment_ajax.php");

echo "<script type='text/javascript'>

function addComment()
{
	document.getElementById('comment').value = 'Processing...';
	
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
	}
	
	var parameters = 'comment='+escape(encodeURI(document.getElementById('comment_box').value))
	+'&phototiding='+escape(encodeURI(document.getElementById('phototiding').value))
	+'&picname='+escape((encodeURI(document.getElementById('picname').value));
	
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('commentable_area').innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open('POST','addtidingcomment.php?pid=".$pid."&tid=".$tidingId."',true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send(parameters);
}
</script>";

//displaying textbox for writing a comment.
echo "
	<div id='comments'>
	
	<div id='comments_pic'>";
			
	$userPic = "SELECT pic FROM user WHERE userid='$uid'";
	$resultUserPic = mysql_query($userPic,$con);
	
	$rowPic = mysql_fetch_array($resultUserPic);							
	
	echo "<img src='crop/".$rowPic['pic']."' width='30px' border='0'/>";
	
	echo "</div>
	
	<form action='addtidingcomment.php?pid=".$pid."&tid=".$tidingId."' method='POST'>
	<div id='comments_content2'>
		
	<textarea name='comment' id='comment_box'></textarea>
		
	</div>
				
	<div id='comments_time' style='padding-top:1px;'>
		<input type='hidden' value='".$photoTiding."' name='phototiding' id='phototiding' />
		<input type='hidden' value='".$picName."' name='picname' id='picname' />
		<input type='button' value='Comment' id='comment' class='button' onClick='javascript:addComment();'/>
	</div>
	
	<div id='continue'></div>
	
</div>";
echo "<span id='commentable_area'></span>";
?>

From the code snippet posted, I think that the issue is with missing ending ')' at the line 35

var parameters = 'comment='+escape(encodeURI(document.getElementById('comment_box').value))
	+'&phototiding='+escape(encodeURI(document.getElementById('phototiding').value))
	+'&picname='+escape((encodeURI(document.getElementById('picname').value));

This is causing Javascript errors and that might be the cause of the issue

The line should be

var parameters = 'comment='+escape(encodeURI(document.getElementById('comment_box').value))
	+'&phototiding='+escape(encodeURI(document.getElementById('phototiding').value))
	+'&picname='+escape((encodeURI(document.getElementById('picname').value)));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.