Newbie_小白
没有都对的别人,也没有全错的自己,至少要有自己的坚持,无关他人、无关外物!

a.php

<?php
$arr1 = array(1, 'heiyeluren', '男18');
echo json_encode($arr1);
?>

 

index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0 ,user-scalable=no">
    <script src="js/jquery.min.js"></script>
    <style type="text/css">
        .wrap {
            margin: 50px;
        }
    </style>
</head>
<body>
<div class="wrap">
    <div>
        <a class='tab-option' data-tab-id='00' href="a.html" onclick="setSess()">首页</a>
        <p id="text"></p>
    </div>
</div>
</body>
<script>
    var back = sessionStorage.getItem('Back');
    if (back != 'Success') {
        getData();
    } else {
        sessionStorage.removeItem('Back');
        setOld();
    }

    function setOld() {
        var backData = JSON.parse(sessionStorage.getItem('BackData'));
        document.getElementById('text').innerHTML = backData[2];
    }

    function setSess() {
        sessionStorage.setItem('Back', 'Success')
    }

    function getData() {
        $.ajax({
            url: 'http://localhost:8088/Demo/data/a.php',
            type: 'get',
            async: true,
            data: {},
            timeout: 5000,
            dataType: 'json',
            beforeSend: function (xhr) {
                console.log(xhr)
                // console.log('发送前')
            },
            success: function (data) {
                console.log(data);
                sessionStorage.setItem('BackData', JSON.stringify(data));
                document.getElementById('text').innerHTML = data[2];
            },
            error: function (xhr, textStatus) {
                // console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                // console.log('结束')
            }
        });
    }
</script>
</html>

 

a.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0 ,user-scalable=no">
    <style type="text/css">
        .wrap{
            margin: 50px;
            width: 2500px;
            height: 2500px;
            background: url('images/30.png') 100% 100%;
        }
    </style>
</head>
<body>
    <div class="wrap">
     <div>
         <div><a href="javascript:window.history.back(-1);">返回上一页</a></div>
         <a href="index.html">页面跳转</a>
     </div>
 </div>
</body>
<script>

</script>
</html>

 

posted on 2017-08-17 11:37  Newbie_小白  阅读(214)  评论(0编辑  收藏  举报