我有一个jquery日历,用于存储日期onselect,我想将所选日期发送到php文件,以便根据所选日期从数据库中获取结果..这是我的代码: -
enter code here<div id="calendar"></div>
日期:
my scripr:-<script>
var 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);
}
}
?>
答案 0 :(得分:1)
$.ajax({ type: "GET",
url: 'check_events.php',
data: { y : x},
//dataType: 'json',
success: function(data)
{
alert(data); //Alert Data on success not result.
}
});
答案 1 :(得分:0)
只需从此处删除不必要的,
:
success: function(data),
所以新代码应该是:
$.ajax({ type: "GET",
url: 'check_events.php',
data: { y : x},
//dataType: 'json',
success: function(data) {
alert(data); //Alert Data on success not result.
}
});