Sunday, 1 September 2013

Jquery ajax Pass post back data to php variable

Jquery ajax Pass post back data to php variable

I have the below script to generate days in month with jq, I want to get
the post back data pass to for loop as condition in php so that it could
populate days in selection box accurately.
Here is how change the days based on year and month
$('#mm').change(function(){
var mm = $(this).val();
var yy = $('#yy').val(); //get the year
var dd = days_in_month(mm,yy);
$.ajax({
type: "POST",
url: 'inc/callback/req_days_in_month.php',
data: { days: dd, },
success: function(data){
//something to do to pass data to php...?
}
});
$('#dd').val(dd);
});
I want $i<=31 replace with postback value from ajax,
<select id="dd">
for($i=1; $i<=31; $i++){
echo '<option value="$i">$i</option>';
}
</select>
req_days_in_month.php:
<?php
$days = $_POST['days'];
echo $days;
?>
Can it possible be done? thanks

No comments:

Post a Comment