$ifvalid
如果true应返回1。在value为真的情况下,它返回10如果我将其正确返回1。为什么这样?
ajax调用
JS -Calling Ajax
var data = {
action: "validate_date",
start_date: 22/2/2017,
end_date: 22/7/2017,
};
$.post(ajaxurl, data, function (response) {
alert(response)
});
php
<?php
function validate_date(){
$start_date = $_POST['start_date'];
$expiration_date= $_POST['end_date'];
$ifValid = check_in_range($start_date, $expiration_date);
echo $ifValid; //returns 10
echo $ifValid;exit; //returns 1
}
function check_in_range($start_date, $end_date)
{
// Convert to timestamp
$start_ts = strtotime($start_date);
$end_ts = strtotime($end_date);
$timeNow = strtotime("now");
// Check that user date is between start & end
return (($timeNow >= $start_ts) && ($timeNow <= $end_ts));
}
?>
在响应此ajax时,我做alert(response);
您可以设置如下
的功能
function check_in_range($start_date, $end_date)
{
// Convert to timestamp
$start_ts = strtotime($start_date);
$end_ts = strtotime($end_date);
$timeNow = strtotime("now");
// Check that user date is between start & end
if(($timeNow >= $start_ts) && ($timeNow <= $end_ts)){
return '1'; // OR return '0'; as you want
}else{
return '0'; // OR return '1'; as you want
}
}