我有一个jquery日历存储日期onselect,我想发送选定的日期到PHP文件从基于选定日期的数据库中获得结果..这是我的代码: -问题通过Javascript变量传递给PHP文件通过Ajax选择
enter code here<div id="calendar"></div>
日期:
my scripr:-<script>
变种X = ''; 。 $( '#日历')日期选择器({
altField: '#datepicker_send',
inline: true,
firstDay: 1,
showOtherMonths: true,
altFormat: "dd/mm/yy",
dateFormat: "dd/mm/yy",
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
onSelect: function(dateText){
$('#event-date').text(dateText)
x=dateText;
// alert(x);
$.ajax({ type: "GET",
url: 'check_events.php',
data: { y : x},
//dataType: 'json',
success: function(data)
{ alert(data); } /// tried to get the value of date
});
}
});
</script>
Check_events.php: -
enter code here<?php mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());
if(isset($_REQUEST['y']))
{
$y = date_format($_REQUEST['y'],'YYYY-MM-DD');
echo $y;
exit; //trying to print the date
//$uname = mysql_real_escape_string($x);
$sql_check = mysql_query("SELECT * FROM events WHERE date='$x'");
while($res=mysql_fetch_assoc($sql_check))
{
print_r($res);
}
}
?>
[**请不要在新代码中使用'mysql_ *'函数**](http://bit.ly/phpmsql)。他们不再被维护[并且被正式弃用](http://j.mp/XqV7Lp)。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://j.mp/PoWehJ)。 – esqew 2014-11-05 06:11:11