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());
                }
            });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看