Reputation:
in this blow code, after printing $tarikh_sal i can see 2012-10-27
correctly, but in $.post
that changed to 1975
, i do not change that. why?
php code
echo $tarikh_sal; //->2012-10-27
if ( $khoms > 0)
{?>
<script>
$.post("actions.php",{ kh:<?php echo $kh;?> , tarikh_sal:<?php echo $tarikh_sal;?> , postaction:'sabte_kh'},
function(data){
alert(data.message);
},'json');
</script>
<?}
FIREBUG:
kh=2397897533&tarikh_sal=1975&postaction=sabte_kh
Upvotes: 1
Views: 82
Reputation:
You need to put quotes around the value, otherwise it is evaluated by Javascript:
'<?php echo $tarikh_sal;?>'
Upvotes: 0
Reputation: 195982
That is because 2012-10-27 = 1975
This happens because in the script it gets printed as tarikh_sal:2012-10-27
and javascript does the math there...
Try putting it in quotes to use it as a string. tarikh_sal:'2012-10-27'
tarikh_sal:'<?php echo $tarikh_sal;?>'
Upvotes: 3
Reputation: 1402
You are not enclosing the date in string format.
echo $tarikh_sal; //->2012-10-27
if ( $khoms > 0)
{?>
<script>
$.post("actions.php",{ kh:'<?php echo $kh;?>' , tarikh_sal:'<?php echo $tarikh_sal;?>' , postaction:'sabte_kh'},
function(data){
alert(data.message);
},'json');
</script>
<?}
Changed :
tarikh_sal:<?php echo $tarikh_sal;?>
to
tarikh_sal:'<?php echo $tarikh_sal;?>'
Upvotes: 1