首先我说下,我是要实现通过2个文本框的值(一个开始时间,一个结束时间,一个搜索按钮)来改变查询结果,结果表就显示在同一个页面的下方。
小弟刚从asp.net转过来了,双击转到后台写代码写习惯了,突然发现这个按钮没法像以前那样去取值,很是悲剧
我的思路是,通过js获取文本的值,并异步传给本页面,同时把获取的值传过去,在php中GET获得,然后动态修改sql语句来实现表格不同内容显示
当然js还是知道一些,但是忘记的差不多了。东拼西凑,写了些不伦不类的代码,经调试,果然失败,请高人指点,谢谢了
代码如下
<td><input name="search" id="search" type="button" value="点击搜索" onclick="new selecttime()"/></td><script language="javascript" type="text/javascript" >
function selecttime()
{
var start_time=document.getElementByID("active_time_start").value;
var end_time=document.getElementByID("active_time_end").value;
if(start_time!=""&&end_time!="")
{
createXmlHttp();
xmlHttp.onreadystatechange=writeAreaInfo;
xmlHttp.open("GET","Pager.php?active_time_start="+start_time+"&&active_time_end="+end_time,ture);
xmlHttp.send(null);
}
}
</script> if(!isset($_GET['active_time_start'])&&empty($_GET['active_time_start'])&&!isset($_GET['active_time_end'])&&empty($_GET['active_time_end']))
{
//默认情况下提取一周事件段为新用户,这里待修改
$sql="select * from data_players"; //注意,这里需优化成只查找需要的字段
echo '1';
}
else
{
$start_time=$_GET['active_time_start'];
$start_time=strtotime($start_time);
$end_time=$_GET['active_time_end'];
$end_time=strtotime($start_end);
$sql="select * from data_players where reg_time>=".$start_time."and reg_time<=".$end_time;
echo $sql;
}问题是我点击搜索,URL根本就没变过- -

解决方案 »

  1.   

    onclick="selecttime()" 直接调用即可你可以通过firefox+firebug调试下,因为ajax请求的url不会体现在浏览器的url中,可以查看下firebug的控制台
      

  2.   

    我的思路是,点击搜索按钮开始执行js,在js中获取文本的值,然后异步转发给服务器,用php的GET获取,然后来动态改变SQL语句,达到同一页面,上面选择条件,下面按条件显示的效果。
    不知道是代码问题还是思路问题,还请各位指点下,谢谢
      

  3.   

    用jquery吧 很简单的
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script language="javascript" type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script>
    function ajax_function(){
    alert("---");
    var s = $("#t").val();
    alert(s);
    $.post("ajaxServer.php",{id:s},rend);
    }
    function rend(xml){
    alert(xml);
    $(".a").html(xml);
    }
    </script>
    </head>
    <body>
    <input type="text" id="t" />
    <input type="button" value="submit" onclick="ajax_function();" />
    <div class="a"></div>
    </body>
    </html>
    <?php
    $id = $_POST['id'];
    echo "ajax返回值$id";
    ?>
      

  4.   


    if(!isset($_GET['active_time_start'])&&empty($_GET['active_time_start'])&&!isset($_GET['active_time_end'])&&empty($_GET['active_time_end']))
        {
    改为:if(empty($_GET['active_time_start']) || empty($_GET['active_time_end'])){}
       还有你数据库连接成功了吗?最好把代码贴全!让大家看看!