简体   繁体   English

在ajax调用中传递php值

[英]Passing php values in an ajax call

so I'm making this deal website. 所以我要制作这个交易网站。 On the index page of the deal website, there would be multiple deals listed and each deal has it's own end date. 在交易网站的索引页面上,将列出多个交易,每个交易都有其自己的结束日期。

Now, I'm using this jQuery script for the clock countdown. 现在,我正在使用此jQuery脚本进行时钟倒计时。

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

This is the database structure 这是数据库结构

Product ID           ProductName    End Date

(auto_increment)       (VARCHAR)      DATE

Now, I guess I would have to put the above jQuery script within a while loop (loop would go through the products, and display their details) to show the clock for each deal. 现在,我想我不得不将上述jQuery脚本放入while循环中(循环将遍历产品并显示其详细信息)以显示每笔交易的时间。

How would I pass a product id (for example let's say the productid is in the $productid variable) in jQuery, so that I can do a mysql query from there to get the end date..and then the clock displays the correct time for each deal. 我如何在jQuery中传递产品ID(例如,产品ID在$ productid变量中),以便可以从那里进行mysql查询以获取结束日期,然后时钟显示正确的时间每笔交易。

Any suggestions are welcome. 欢迎任何建议。

If you are planing to use php as a server side language, I would suggest to add another two fields to the table "initial date" and "for how long the deal will be available" and then subtract the time. 如果您打算将php作为服务器端语言使用,我建议在表“初始日期”和“可进行交易的时间长短”中添加另外两个字段,然后减去时间。 every time that the user enters to your web site you echo the result of the subtraction. 每次用户进入您的网站,您都会回显相减的结果。 You can manipulate this with jquery to display it as a countdown. 您可以使用jquery进行操作,以将其显示为倒计时。

You can use jquery ajax, so get correct date from php file via jquery ajax and set it into $('#defaultCountdown').countdown({until: austDay}); 您可以使用jquery ajax,因此可以通过jquery ajax从php文件中获取正确的日期,并将其设置为$('#defaultCountdown').countdown({until: austDay}); . If you want get date peridly from php file so u can use javascript setTimeOut. 如果您想从php文件中获取日期,那么您可以使用javascript setTimeOut。

jquery ajax jQuery的ajax

settimeout 设置超时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM