duankui1532 2016-08-14 13:07
浏览 66

Jquery获取数据是否没有返回到重定向页面?

I have three php pages and two javascript/jquery functions.

Search.php:
In this page jquery Get data is sending data to LikeMail.php by clicking img tag embedded in anchor tag. Both and also other html contents inside while loop are generated dynamically. After sending jquery get data to LikeMail.php it then calls that php page by ajax call. Both jquery and ajax are working fine in this page. Jquery sending data correctly and receives data by ajax correctly.

<?php
session_start();
include("db.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Blog</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="main.css">
    <script src="jquery-1.12.2.min.js"></script>
    <script src="js/bootstrap.min.js"></script>

    <script src="user2.js"></script>

    <style>
        p.col-lg-2{
          font-family: "Comic Sans MS";
        }
    </style>
</head>
<body>



<div class="container">
    <nav class="navbar nav-top navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="collapse navbar-collapse" id="myNavbar">
                <ul class="nav navbar-nav">
                    <li class="link one"><a href="index.php">Home</a></li>
                    <li class="link">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">Blog</a>
                    </li>
                    <li class="link"><a href="#">FAQ</a></li>
                    <li class="link"><a href="#">Terms & Cond</a></li>
                    <li class="link"><a href="#">Contact</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li class="one"><a href="logout.php">Logout</a></li>
                </ul>
            </div>
        </div>
    </nav>


    <!--Navbar-->



    <div class="row topsecond">
        <div class="col-lg-12">
            <h3 class="heading">Ads</h3>
        </div>
    </div>

    <!--Ads-->


    <div class="row">
        <div class="col-lg-8">
            <div class="col-lg-3 col-sm-5">
                <a type="button" href="userOwnProfile.php" class="btn btn-lg btn-primary">My Profile</a>
            </div>
            <div class="col-lg-3 col-sm-5">
                <button type="button" class="btn btn-lg btn-primary">Women List</button>
            </div>
            <div class="col-lg-3 col-sm-5">
                <button type="button" class="btn btn-lg btn-primary">Message List</button>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="col-lg-6 col-sm-5">
                <a href="#">
                    <button type="button" class="btn btn-lg btn-primary">New Likes</button>
                </a></div>
            </a>
            <div class="col-lg-6 col-sm-5">
                <button type="button" class="btn btn-lg btn-primary">New Message</button>
            </div>
        </div>
    </div>

    <div class="col-lg-12 col-sm-12">
<div class="row">
        <h3 class="heading"><u>MEN'S LIST - Filter Search Result by:</u></h3>
</div>
        <div class="row">
<!--            <label class="control-label col-xs-12 col-lg-1" for="pwd"> State Living: </label>-->
            <!--<div class="col-xs-8 col-xs-offset-1 col-lg-2">
                <select class="form-control col-lg-1">
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>-->

            <div class="control-label col-xs-12 col-lg-2">
                <label for="age from">
                    Country
                </label>
                <select class="form-control col-lg-2">
                    <option selected>All</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>

            <!--<label class="control-label col-xs-12 col-lg-1" for="pwd">State Living:</label>
            <div class="col-xs-8 col-xs-offset-2 col-lg-2">
                <select class="form-control col-lg-3">
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>-->
            <div class="control-label col-xs-12 col-lg-2">
                <label for="age from">
                    State Origin
                </label>
                <select class="form-control col-lg-2">
                    <option selected>Choose</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>

            <!--<label class="control-label col-xs-12 col-lg-1" for="pwd">State Living:</label>
            <div class="col-xs-8 col-xs-offset-2 col-lg-2">
                <select class="form-control ">
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>-->

            <div class="control-label col-xs-12 col-lg-2">
                <label for="age from">
                    State Living
                </label>
                <select class="form-control col-lg-2">
                    <option selected>Choose</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>

            <!--<label class="control-label col-xs-12 col-lg-1" for="pwd">State Living:</label>
            <div class="col-xs-8 col-xs-offset-2 col-lg-2">
                <select class="form-control ">
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>-->


            <div class="control-label col-xs-12 col-lg-2">
                <label for="age from">
                    Marital Status
                </label>
                <select class="form-control col-lg-2">
                    <option selected>Choose</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>

            <!--<label class="control-label col-xs-12 col-lg-1" for="pwd">State Living:</label>
            <div class="col-xs-8 col-xs-offset-2 col-lg-2">
                <select class="form-control col-lg-3">
                    <option>1</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>
        </div>
-->


            <div class="control-label col-xs-12 col-lg-2">
                <label for="age from">
                    Marital Status
                </label>
                <select class="form-control col-lg-2">
                    <option selected>Choose</option>
                    <option>2</option>
                    <option>3</option>
                    <option>4</option>
                    <option>5</option>
                </select>
            </div>


        <div class="col-xs-6 col-lg-1">
                <label for="age from">
                    Age from
                </label>
                <input class="form-control" type="text">
                </div>
            <div class="col-xs-6 col-lg-1">

                <label for="age to">
                    Age to
                </label>
                <input class="form-control" type="text">
                </div>


        </div>
    </div>



    <div class="col-lg-4">

    </div>

<div class="row">



    <div class="col-lg-2">


    </div>



    <div class="col-lg-12">


        <?php
        $query = mysqli_query($conn, "SELECT * FROM user");

        while ($record = mysqli_fetch_array($query)) {

        if ($record == FALSE) {
            die(mysqli_error("error message for the user"));
        }

        ?>


        <div style="border: 1px dotted black;" class="row" id="call">

            <div style=" border: 1px solid white" class="col-lg-2">
                <!--<img src="images/team-hire.jpg" style="background-size: cover" width="85%" height="90%">-->



                <a class="profile" href="<?php echo "viewProfile.php?id=" . $record['user_id'];?>" >
                    <img class="img-rounded"
                         src=" <?php echo "../shadi/images/" . $record['user_photo1'] ?>"
                         id="<?php echo $record['user_id']; ?>"alt="" width="70%" height="20%">

                </a>





            </div>

            <p class="col-lg-2 col-xs-12 col-xs-offset-6">
                <?php echo $record['user_educationLevel'];  ?>
            </p>

            <p class="col-lg-2 col-xs-12">
                <?php echo $record['user_career'] ?>
            </p>

            <p class="col-lg-2 col-xs-12">

                <?php echo $record['user_stateLiving'] ?>
            </p>

            <p class="col-lg-2 col-xs-12">
                <?php echo $record['user_stateOfOrigin'] ?>
            </p>

            <p class="col-lg-2 col-xs-12">
                <?php echo $record['user_religion'] ?>
            </p>

        </div>
            <?php
        }
        ?>
    </div>

</div>

</div>


</body>
</html>



LikeMail.php:
jquery get data is being sent in this page. After some processing, it then shows out put which then returns through ajax call in desired pages

viewProfile.php:
This is the page where problem exists. it is basically redirected page. Its url is stored in anchor tag in Search.php page. In this page ajax is returning wrong data from LikeMail.php as jquery get data which we have sent earlier through Search.php is not returning in this page.

    <html>
<head>

</head>
</html>
<?php
session_start();
include("db.php");
if(!isset($_SESSION['login'])) {
    header("Location:Login.php");


}
else {
    $user1 = $_SESSION['user_id'];

    if ($user_id == "") {

        header("location:index.php");
    } else {


//echo $user_id;
//$user_id = 14;
        $user_email = $_SESSION['user_email'];

        /*$sql = "UPDATE user SET user_onlineStatus= . NOW() . WHERE user_id=14";

        $setLogged = mysqli_query($conn, $sql);*/
//echo $_SESSION['user_id'];

        ?>
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>User's Own Profile</title>
            <link rel="stylesheet" href="css/bootstrap.min.css">
            <link rel="stylesheet" href="main.css">
            <script src="js/jquery-1.12.2.min.js"></script>
            <script src="js/bootstrap.min.js"></script>
            <script src="bootstrap-3.3.6-dist/js/jquery-1.12.2.min.js"></script>
            <script src="bootstrap-3.3.6-dist/js/bootstrap.min.js"></script>
            <!--<script src="js/custom.js"></script>-->

            <script src="test.js"></script>
        </head>
        <body>

        <div class="container">
        <nav class="navbar nav-top navbar-inverse">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav">
                        <li class="link one"><a href="index.php">Home</a></li>
                        <li class="link">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Blog</a>
                        </li>
                        <li class="link"><a href="#">FAQ</a></li>
                        <li class="link"><a href="#">Terms & Cond</a></li>
                        <li class="link"><a href="#">Contact</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="one"><a href="logout.php">Logout</a></li>
                    </ul>
                </div>
            </div>
        </nav>


        <!--Navbar-->


        <div class="row topsecond">
            <div class="col-lg-12">
                <h3 class="heading">Ads</h3>
            </div>
        </div>

        <!--Ads-->


        <div class="row">
            <div class="col-lg-8">
                <div class="col-lg-4 col-sm-5">
                    <a type="button" href="userOwnProfile.php" class="btn btn-lg btn-primary">My Profile</a>
                </div>
                <div class="col-lg-4 col-sm-5">
                    <a type="button" href="Search.php" class="btn btn-lg btn-primary">Find People</a>
                </div>
                <div class="col-lg-4 col-sm-5">
                    <button type="button" class="btn btn-lg btn-primary">Message List</button>
                </div>
            </div>

            <div class="col-lg-4">
                <div class="col-lg-6 col-sm-5">
                    <a href="#">
                        <button type="button" class="btn btn-lg btn-primary">New Likes</button>
                    </a></div>
                </a>
                <div class="col-lg-6 col-sm-5">
                    <button href="index.php" type="button" class="btn btn-lg btn-primary">New Message</button>
                </div>
            </div>
        </div>


        <!--Links-->


        <div class="col-lg-8 left">

        <div class="row">
        <div class="row ">
        <?php
        //           include("db.php");
        //$user_id = 14;
        $photo = mysqli_query($conn, "SELECT * FROM user WHERE user_id='$user_id'");

        while ($recordPhoto = mysqli_fetch_array($photo)) {

            if ($recordPhoto == FALSE) {
                die(mysqli_error("error message for the user"));

            }

            ?>
            <div class="col-lg-4 col-sm-4 col-xs-4 img">

                <img class="img-rounded" src="<?php echo "../shadi/images/" . $recordPhoto['user_photo1'] ?>" alt=""
                     width="100%" height="40%">
            </div>

            <?php if($recordPhoto['user_photo2']!=""){

             ?>

            <div class="col-lg-4 col-sm-4 col-xs-4 img">
                <img class="img-rounded" src="<?php echo "../shadi/images/" . $recordPhoto['user_photo2'] ?>" alt="" width="100%" height="40%">
            </div><?php }
            else
            {
                echo "";
            }
            if($recordPhoto['user_photo2']!=""){


            ?>

            <div class="col-lg-4 col-sm-4 col-xs-4 img">
                <img class="img-rounded" src="<?php echo "../shadi/images/" . $recordPhoto['user_photo3'] ?>" alt="" width="100%" height="40%">
            </div>
            <?php }
            else
            {
                echo "";
            }
            ?>
            </div>


            <div class="row upload">
                <div class="col-lg-6 col-sm-5 col-xs-12">

                    <div id="Like"></div>//This is the div where ajax data is returning through LikeMail.php
                </div>


                <a href="indexchat.php?chat=<?php echo $user_id; ?>">
                    <div class="col-lg-6 col-sm-5 col-xs-12">
                        <div class="btn btn-lg btn-info edit">
                            <span class="glyphicon glyphicon-comment"></span> Messages
                        </div>
                    </div>
                </a>

            </div>
            </div>
            <?php
            $res = mysqli_query($conn, "SELECT * FROM user WHERE user_id=$user_id");

            while ($record = mysqli_fetch_array($res)) {

                if ($record == FALSE) {
                    die(mysqli_error("error message for the user"));

                }
                ?>
                <div class="col-lg-12 col-sm-12">
                    <div class="row">
                        <h3 class="heading col-sm-4">PROFILE</h3>

                        <div class="col-sm-8">
                            <h3><?php echo $record['user_name']; ?></h3>
                        </div>
                    </div>
                    <div class="">
                        <div class="row">
                            <h4 class="col-lg-4 col-sm-4 col-xs-4">Gender :</h4>

                            <div class="col-lg-6 col-sm-6 col-lg-6 col-xs-4 col-xs-8">
                                <h5><?php echo $record['user_gender']; ?></h5>
                            </div>
                        </div>
                    </div>

                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Date of Birth :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_dob']; ?></h5>
                            </div>
                        </div>
                    </div>

                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Age :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-4 col-sm-6 col-lg-6 col-xs-4 col-xs-12">
                                <h5>31 years</h5>
                            </div>
                        </div>
                    </div>

                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Height :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_height']; ?></h5>
                            </div>
                        </div>
                    </div>

                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Weight :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_weight']; ?></h5>
                            </div>
                        </div>
                    </div>
                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Race :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_race']; ?></h5>
                            </div>
                        </div>
                    </div>
                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Religion :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_religion']; ?></h5>
                            </div>
                        </div>
                    </div>
                    <br>

                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Country :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5> <?php echo $record['user_country']; ?></h5>
                            </div>
                        </div>
                    </div>


                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">State Origin :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5>  <?php echo $record['user_stateOfOrigin']; ?>
                                </h5></div>
                        </div>
                    </div>


                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">State Living :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5> <?php echo $record['user_stateLiving']; ?></h5>
                            </div>
                        </div>
                    </div>


                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Marital Stauts :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_maritalStatus']; ?></h5>
                            </div>
                        </div>
                    </div>

                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Career :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_career']; ?></h5>
                            </div>
                        </div>
                    </div>

                    <div class="">
                        <div class="row">
                            <h4 class=" col-sm-4 col-lg-4 col-xs-4">Educational Level :</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_educationLevel']; ?></h5>
                            </div>
                        </div>
                    </div>
                    <br>

                    <div class="">
                        <div class="row">
                            <h4 class="col-sm-4 col-lg-4 col-xs-4">Relations for</h4>

                            <div class="col-sm-6 col-lg-6 col-xs-6">
                                <h5><?php echo $record['user_relationshipfor']; ?></h5>
                            </div>
                        </div>
                    </div>

               </div>

                    <div class="row">
                        <h4 class=" col-sm-4 col-lg-4 col-xs-4">Self Summary : <br>
                        </h4>

                        <div class="col-sm-6 col-lg-6 col-xs-6">
                            <h5><?php echo $record['user_selfSummary']; ?></h5>
                        </div>
                    </div>
                    <br>


                    <div class="row">
                        <div class="col-sm-4">

                        </div>
                        <!--<div class="col-sm-8">
                            <button type="button" class="btn btn-lg btn-warning">Submit</button>
    <div class="respond"></div>
</body>
    </html>
    <?php
}
    ?>



user2.js:
This is jquery function of get in user2.js page

$(document).ready(function () {
    $('.profile').on('click', function (e) {

        //Get the href Link
        var href = $(this).attr('href');

        e.preventDefault();
        $.get("LikeMail.php",
            {user2: $(this).find(".img-rounded").attr("id")}, function (returnedData) {

                // Do whatever you want with returend data
                console.log(returnedData),

                function(){
                    console.log('error');
                }


            }).done(function () {
            //Redirecting to anchor destination.
            window.location.href = href;

        });

    });

});




test.js:
This ajax function in test.js
function like()
    {
    var req  = new XMLHttpRequest();
    req.onreadystatechange = function()

    {
        if(req.readyState==4 && req.status==200)
        {
            document.getElementById('Like').innerHTML=req.responseText;

        }
    }
    req.open('GET','LikeMail.php','true');
    req.send();
}
setInterval(function(){like()},1000);

I want ti know why jquery get data is not receiving in vieProfile.php page after redirecting through anchor tag in Search.php
Update:
Ajax is returning in <div id="Like"></div> in viewProfile.php

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值