Jquery datepicker与Ajax不起作用 [英] Jquery datepicker with Ajax is not working

查看:139
本文介绍了Jquery datepicker与Ajax不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上有很多类别。每个类别页面都有他们的帖子。在这里我使用jQuery datepicker,如果用户想看到8月20日的帖子,他们点击calender&看日期帖子。还有一件事,如果我打开一个类别,今天的职位只能显示。请检查此代码并帮助我。此代码显示所有类别& datepicker没有检索任何东西。

In my website there are many categories. Each category page have their posts. Here I used jQuery datepicker, if user want to see Aug 20th posts, they click particular date on calender & see the date posts. One more thing, if I open one category the posts of today should be displayed only. Please check this code and help me. This code displays all posts of category & datepicker is not retrieving anything.

这是在function.php中的mysql查询

This is mysql query in function.php

 if(isset($_REQUEST['datepost']))
 {
 $date = $_POST['date'];

 $res=mysql_query("SELECT * FROM  `wp_posts` WHERE DATE_FORMAT(post_date,  '%m/%d/%Y' ) =  '%m/%d/%Y' AND post_type = 'post'  ORDER BY post_date DESC");
 $pageposts=mysql_fetch_array($res);

 exit();
 }  
 ?>

这是我的脚本& PHP代码:

This is my script & PHP code:

 <script type="text/javascript">
 $(function() {
 <!--current date posts-->
     var currentTime = new Date();
     var day = currentTime.getDate();
     var month = currentTime.getMonth() + 1;
     var year = currentTime.getFullYear();

    if (day < 10) {
            day = "0" + day;
    }

    if (month < 10) {
            month = "0" + month;
    }

    var today_date = day + "/" + month + "/" + year;
    var dataString ='date='+today_date;

 $.ajax ({
          type: "POST",
          url: "<?php echo home_url(); ?>/?datepost",
          data: dataString,

          success: function(data) {
              $('#testdiv').html(data);
          }
            });     <!--End current date posts-->


 <!--select date posts-->
    $("#datepicker").datepicker ({
            onSelect: function(dateTypeVar, inst) {
                    var dateAsObject =   $(this).val();
                    var dataString ='date='+dateAsObject;
                    $.ajax ({
          type: "POST",
          url: "<?php echo home_url(); ?>/?datepost",
          data: dataString,
          success: function(data) {

              $('#testdiv').html(data);
          }
            });  <!--End select date posts-->
    }
    });
 });
 </script>

PHP编码:

 Date: <input type="text" id="datepicker" size="30"/>
  <?php while (have_posts()) :the_post();

 ?>
     <div id="testdiv"> 
  <div class="featuredpost">


 <div class="cat-block">
         <a href="<?php echo the_permalink();?>" rel="bookmark"> <?php the_post_thumbnail( 'homepage-catpage' ) ?></a>

         <h2 class="posttitle"> <a href="<?php echo the_permalink();?>" rel="bookmark" title="" ><?php echo $key_1_values = get_post_meta($postid, '_visual-subtitle', true ); ?></a>
         </h2>

              <p> <?php $content = get_the_excerpt();
                                   $contentrecord=htmlspecialchars_decode(strip_tags(stripslashes($content)));
                           echo substr($contentrecord, 0, 350); ?></p>
          <p class="postmeta"><span class="meta_date"><?php the_time('Y/m/d g:i:s A'); ?>
          <input id="name" type="hidden" value="<?php echo $postid; ?>" name="post__id">
          <p>

          </span><span class="meta_permalink"><a href="<?php echo the_permalink(); ?>" title="111" rel="bookmark">التفاصيل</a>     </span>     </p>

 </div>


 </div>
 </div>  


 <?php endwhile;
 wp_reset_query();?>
 </div>    


推荐答案

<?php if(isset($_REQUEST['datepost']))
 {
 $date = date('m/d/Y',strtotime($_POST['date']));

 $res=mysql_query("SELECT * FROM  `wp_posts` WHERE DATE_FORMAT(post_date,  '%m/%d/%Y' ) =  $date AND post_type = 'post'  ORDER BY post_date DESC");
 $pageposts=mysql_fetch_array($res);

 exit();
 }  
?>

为DATE_FORMAT(post_date,'%m /%d /%Y')提供post_date列的实际值)= $ date

Provide actual value for post_date column like DATE_FORMAT(post_date, '%m/%d/%Y' ) = $date

这篇关于Jquery datepicker与Ajax不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆