douchengchen7959 2014-03-19 16:14
浏览 34
已采纳

在jQuery倒计时中通过mysql获取结束日期

so I have this jQuery script which I'm using for a jQuery countdown.

<script>
$(function () {
    var austDay = new Date();
    austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
    $('#defaultCountdown').countdown({until: austDay});
    $('#year').text(austDay.getFullYear());
});
</script>

But the date here is hardcoded. What I want is, that I want to get the end time from a mysql database and then use it in jQuery. How would I do that ?

Here's my database structure

Product ID           ProductName    End Date

(auto_increment)       (VARCHAR)      DATE
  • 写回答

1条回答 默认 最新

  • dongmian5325 2014-03-19 16:41
    关注

    You would need a PHP script which looks up the date you need according to certain query parameters you specify, if necessary, in the URL and then the PHP would use echo to output that date from MySQL.

    Finally, JavaScript/jQuery would need to do an AJAX request to the PHP script, where it will fetch the date as a string in its response, and then you can use it in your JavaScript code:

    $.ajax({
                type:'GET',
                url: 'your_mysql_date_fetcher.php',
                data: "product_id=5&ProductName=example_name",
                success:function(data){
                    var austDay = new Date(data);
                    $('#defaultCountdown').countdown({until: austDay});
                    $('#year').text(austDay.getFullYear());
                }
            });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?