从第二页导航到第一页的php页面没有显示正确的div

时间:2014-04-19 09:41:37

标签: javascript php jquery html css

我有第一个php页面,其中有一些复选框。我选择复选框和页面中存在的div被过滤,当过滤后,我点击一个div并导航到第二个php页面。其中我显示了详细信息但是,当我从浏览器按下后退按钮并导航到第一页时。我在这里遇到的问题是当我导航回上一页时,复选框被检查它们只被检查但div不被过滤。

firstpage.php

    <html>
    <head>
    <title>Insert title here</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    </head>
    <body>

    <script type="text/javascript">
        function get_check_value() {
            var c_value = [];

            $('input[name="brand"]:checked').each(function () {
                c_value.push(this.value);
            });
            return c_value.join(',');

        }
        function get_store_value(){
        var d_value=[];
            $('input[name="store"]:checked').each(function () {
                d_value.push(this.value);
            });
            return d_value.join(',');
            }

    $(document).ready(function(){
   checkboxValidate = function (e) {
   if(e)e.preventDefault();
    alert("hi");
        //var os = $('#originState').val();
       //var c = $('#commodity').val();
        //var ds = $('#destState').val();
        var ser = get_check_value();
        var store=get_store_value();
        //var queryString = "os=" + os;
        var data = "?ser=" + ser;
        var queryString = "&ser=" + ser;
        alert(ser);
       $.ajax({
       //alert("ajax");
        type: "POST",
        url: "sortingajax.php",
        data: {ser:ser,store:store},
        dataType :  'html',
        success: function (b) {
           // alert(a+' ok. '+b)
            $('#results').html(b);
            console.log(b);
        }
    });

    } 
    $( "[type=checkbox]" ).change(checkboxValidate);
    checkboxValidate
});
    </script>


    brand
        <input type="checkbox" name="brand" value="Sunbaby" id="check" />Sunbaby
        <br/>
        <input type="checkbox" name="brand" value="Advance Baby" id="check"/>Advance Baby
        <br/>
        store
        <br/>
        <input type="checkbox" name="store" value="Flipkart" id="check"/>Flipkart
        <br/>
        <input type="checkbox" name="store" value="Supermart" />Suoermart
        <br/>
        <input type="checkbox" name="store" value="Target" />Target
        <br/>


    <button id="btnSubmit">sort</button>
    <?php
    $secondsql ='SELECT * FROM xml WHERE  ('.implode ('AND',$parts).')limit '.$offset.', '.$limit1.'';
    //print($secondsql);
    $sql2=mysql_query($secondsql);
    $nameArray2=array();
    //echo "<br />";
    //echo $numrows;
    while($row = mysql_fetch_array($sql2)) {
        // Append to the array


        $nameArray2[] = $row;



        //echo $row['PID']."<BR />";
    }

    foreach($nameArray2 as $array)
    {$i = 1;
    ?>
    <div>
    <a href="secondpage.php?name=<?php $array['IMAGEURL']?>">iMAGELINK</a></div>
    <?php
    }
    $i++;
    ?>

    <div id="results">
    </div>
    </body>
    </html>

sortingajax.php

 <?php

include('connection.php');
$query=$_POST['ser'];
$query1=$_POST['store'];
echo $query;
echo $query1;

$query=explode(",",$query);
$query = array_filter($query);
$query1=explode(",",$query1);
$query1 = array_filter($query1);
$result=count($query);
$result1=count($query1);
//echo $result;
echo $result1;
$parts = array();
$limit = 10;
    $offset = 0;
if(!empty($query))
{
foreach( $query as $queryword ){
    $parts[] = '`BRAND` LIKE "%'.$queryword.'%"';

}
$brandsql='SELECT * FROM XML WHERE  ('.implode ('OR',$parts).')  order by price asc';
    $brandsql1=mysql_query($brandsql);
$numrows = mysql_num_rows($brandsql1);  
$countArray=array();
print($brandsql);
echo "<br />";
while($row = mysql_fetch_array($brandsql1)) {
    // Append to the array


    $countArray[] = $row;



    //echo $row['PID']."<BR />";
}
}
$parts1=array();
if(!empty($query1)){
foreach( $query1 as $queryword1 ){
    $parts1[] = '`STORE` LIKE "%'.$queryword1.'%"';

}
$storesql='SELECT * FROM XML WHERE  ('.implode ('OR',$parts1).') order by price desc';
    $storesql1=mysql_query($storesql);
$numrows1 = mysql_num_rows($storesql1); 
$countArray=array();
print($storesql);
while($row = mysql_fetch_array($storesql1)) {
    // Append to the array


    $countArray[] = $row;



    //echo $row['PID']."<BR />";
}
}
?>


<?php
foreach($countArray as $array)
{



?>

<div>
<a href="secondpage.php?name=<?php $array['IMAGEURL']?>">iMAGELINK</a></div>

<?php $i++; } ?>

Secondphp页面

<?php
$IMAGE=$_GET['name'];
?>
<html>
<head>
</head>
<body>
<img src="<?php echo $IMAGE?>"/>
</body>
</html>

在第一页,当我选中任何复选框时,使用ajax调用图像链接存在于页面中。然后我点击任何链接并将其传递到第二个php页面。显示图像。但是当我按下后退按钮,并转到第一页。检查shpws复选框,但不过滤div。 如果需要更多信息,请帮助我..并评论。

1 个答案:

答案 0 :(得分:0)

用这个替换你的就绪功能:

$(document).ready(function(){
   checkboxValidate = function (e) {
   if(e)e.preventDefault();
    alert("hi");
        //var os = $('#originState').val();
       //var c = $('#commodity').val();
        //var ds = $('#destState').val();
        var ser = get_check_value();
        var store=get_store_value();
        //var queryString = "os=" + os;
        var data = "?ser=" + ser;
        var queryString = "&ser=" + ser;
        alert(ser);
       $.ajax({
       //alert("ajax");
        type: "POST",
        url: "sortingajax.php",
        data: {ser:ser,store:store},
        dataType :  'html',
        success: function (b) {
           // alert(a+' ok. '+b)
            $('#results').html(b);
            console.log(b);
        }
    });

    } 
    $( "[type=checkbox]" ).change(checkboxValidate);
    checkboxValidate();
});

请注意,此处的技巧是在复选框值更改时进行过滤。但是当您打开页面并且已经选中了复选框时,您需要再次运行相同的脚本进行过滤。