I’m trying to post data from this script to a test page which contains my INSERT QUERY , I’m trying to post Subject and ID , but I am able to send only subject, not the ID, this ID is a variable in PHP and this script and PHP variable are on the same page. but when I try to pass the ID manually to the insert query it is working and inserting the subject data.
I think I am not able to transport the PHP var into Jquery properly.
I used Json_encode also but that also didn’t work. I am new to this, I do not know too much about details.
$(function() {
var subject;
var dataString;
var id;
$(".notes").click(function() {
id = <?php echo $id;?>;
subject = $("#textarea").val();
dataString = 'subject='+ subject ;
if(subject=='')
{
$('.ryt').fadeOut(1000).hide();
$('.ntryt').fadeIn(1000).show();
$('.ntryt').fadeOut(5000).show();
}
else
{
$.ajax({
type: "POST",
url: "/test.php",
data:{dataString,id}
success: function(){
$('.ryt').fadeIn(1000).show();
$('.ryt').fadeOut(2000).show();
$('.ntryt').fadeOut(200).hide();
}
});
}
return false;
});
});
data:{dataString,id}is not valid.It should be: