I want to pass variable from javascript to php using POST and I am doing something like the following. I view1.php
<script>
function testing(col) {
$("#bookId").val(col);
$.ajax({
type: 'POST',
url: <?php echo Yii::app()->createUrl('siteaccess/create') ?>,
data: {ad_id:<?php echo "hello" ?>},
success: function(col){console.log(col)},
});
}
</script>
In same file I have following code calling testing()
function(){
testing($(this).parent().parent().children(\':nth-child(2)\').text());
}
In create.php I have
<?php
$v = $_POST['ad_id'];
echo $v;
?>
For create.php I am getting this error "Undefined index: ad_id". Can anyone guide where I am making mistake?