我只想在sql database

时间:2016-05-09 07:23:07

标签: javascript php jquery

我已经开发了一个投票系统,所以我想知道你是否能帮我解决这个问题。我已经使用setinterval的javascript查询每2秒后加载数据但是我试图这样做但是没有发生它不适合我可以任何人帮助我没有发现错误当我检查它不是显示更新的数据

脚本

$(document).ready(function() {
$.ajaxSetup({ cache: false });
setInterval(function(){
    var req = new XMLHttpRequest;
    var url = "includes/votings.php";
    var vars = "records=records&gender=Female";
    req.open("POST", url, true);
    req.setRequestHeader("Content-Type", "x-www-form-urlencoded");
    req.onreadystatechange = function() {
        if(req.readyState == 4 && req.status == 200) {
            var returndata = req.responseText;
            var currenttime = myDate.getTime();
            if(currenttime > returndata) {
                $.ajaxSetup({ cache: false });
                setInterval(function(){$("#ratewomen").load("includes/votings.php?vt=home&gender=Female");},100);
            }
        }
    }
},2000);
});

这是我的PhP代码

<?php 
if(isset($_POST['records'])) {
    $gender = $_POST['gender']; 
    $query  = mysqli_query($connection, "SELECT * FROM profile WHERE gender = '".$gender."' AND status = 'approved' AND votes > 0 ORDER BY votes DESC LIMIT 1");
    $data   = mysqli_fetch_array($query);
    echo $data[4];
}
?>

2 个答案:

答案 0 :(得分:0)

您可以将Jquery用于刷新div。

 $('.your_button').on('click', function(){
         $('#divLogin').load('your_page_url_here');
    });

答案 1 :(得分:0)

试试这个...... `

    <?php 
       if(isset($_GET['records'])) {
       $gender = $_GET['gender']; 
       $query  = mysql_query("SELECT * FROM profile WHERE gender = '$gender' 
       AND   status = 'approved' AND votes > 0 ORDER BY votes DESC LIMIT 1");
       $data   = mysql_fetch_array($query);
       echo $data[4];
      }
      ?>
`