<!DOCTYPE html>
<html lang="en">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <title>share a secret</title>
</head>

<body>
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <h1 style="text-align:center">分享一個秘密</h1>
                <hr>

                <textarea class="form-control" id="" cols="30" rows="5" placeholder="獻上你的祕密吧!"></textarea>
                <br>
                <button id="submit" class="btn btn-primary btn-lg btn-block">送出秘密</button>

                <hr>

                <div class="panel panel-default">
                    <div class="panel-heading">別人的秘密</div>
                    <div id="secret" class="panel-body">
                        想要祕密嗎?先獻上你的祕密吧!
                    </div>
                </div>

            </div>
        </div>
    </div>

    <script>
        $(function () {
            $("#submit").click(function (e) {
                $.ajax({
                    type: "POST",
                    url: "/secret",
                    data: { secret: $("textarea").val() },
                    dataType: "json",
                    success: function (response) {
                        $("#secret").html(response.secret);
                    }
                });
            });
        });
    </script>

</body>

</html>

results matching ""

    No results matching ""