0

あなたの助けが必要です。私のphpコードでは、日付のカウントダウンを作成しました。すべて機能しますが、jqueryのコードに問題があります。$json_result 値を取得しようとしています。これは私のphpコードです:

<?php
function addZero($addZero){
        return ($addZero < 10) ? '0'.$addZero : $addZero;
    }

header('Content-type: application/json');

$year_value = date('Y');
$end_month = $_GET['month'];
$end_day = $_GET['day'];
$end_hours = $_GET['hour'];

$date = strtotime("$year_value-$end_month-$end_day, $end_hours:00:00");
$remaining = $date - time();
$minutes = floor($remaining/60);
$hours = floor($remaining/3600);
$daysLeft = floor($remaining/86400);

if($daysLeft > 0){
        $remaining_hours = $hours - ($daysLeft * 24);
    }else{
        $remaining_hours = $hours;
    }

$remaining_minutes = floor(($remaining - ($hours * 3600))/60);
$remaining_seconds = floor($remaining - ($minutes * 60));

$result = 'Days left:&nbsp;'.$daysLeft.'&nbsp;'.addZero($remaining_hours).':'.addZero($remaining_minutes).':'.addZero($remaining_seconds);
$json_result = json_encode($result);
echo $json_result;
?>

そして、これは私のhtml jquery phpコードです:

<head>
<script type="application/javascript">
jQuery(document).ready(function(){
    $("#submit").click(countDown);
});

function countDown(e){
    setTimeout(function(){
        $.get('countdown.php',function(data){
        $("#countDown").html(data);
        e.preventDefault(); 
        });
        countDown();
    },1000);    
}
</script>
</head>
<body>
<?php
$monthsArray = array(0 => '0', 1 => 'Jan.', 2 => 'Feb.', 3 => 'Mar.', 4 => 'Apr.', 5 => 'May', 6 => 'Jun.', 7 => 'Jul.', 
8 => 'Aug.', 9 => 'Sep.', 10 => 'Oct.', 11 => 'Nov.', 12 => 'Dec.');
$months = array_slice($monthsArray, date('m'), 12, true);
?>
<label>Month:</label>
<select name="month" id="month">
    <?php
        foreach ($months as $values => $keys) {
            printf('<option value="%u">%s</option>', $values, $keys);        
        }
    ?>
</select>
<?php
$daysArray = array(0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => '10', 
11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15', 16 => '16', 17 => '17', 18 => '18', 19 => '19', 20 => '20', 21 => '21', 
22 => '22', 23 => '23', 24 => '24', 25 => '25', 26 => '26', 27 => '27', 28 => '28', 29 => '29', 30 => '30', 31 => '31');

    if(date('L') == 0 && (date('m') == 02 || date('m') == 2)){
        $days = array_slice($daysArray, date('d'), -3, true); // if it's not a leap year february has 28 days
    }elseif(date('L') == 1 && (date('m') == 02 || date('m') == 2)){
        $days = array_slice($daysArray, date('d'), -2, true); // if it's a leap year february has 29 days
    }elseif(date('m') % 2 == 0){
        $days = array_slice($daysArray, date('d'), -1, true); // even month
    }else{
        $days = array_slice($daysArray, date('d'), 31, true); // odd month
    }
?>
<label>Day:</label>
<select name="day" id="day">
    <?php
        foreach ($days as $values => $keys) {
            printf('<option value="%u">%s</option>', $values, $keys);        
        }
    ?>
</select>
<input type="submit" id="submit"  value="Submit">
<div id="countDown">
</div>
</body>

誰かが私が間違っていることを教えてもらえますか?? そして、jquery バージョン 1.9.1 を使用しています。

4

2 に答える 2