科技馆抢票协议

42 篇文章 9 订阅
32 篇文章 1 订阅

为了演示预约门票逆向协议的部分代码,我们可以假设有一个简单的流程,用户通过前端表单提交数据,后端处理请求并返回一个预约确认信息。这段代码会展示前端和后端的基本实现。

### 前端 (HTML + JavaScript)

首先,我们创建一个简单的前端表单,用户可以在这里输入他们的姓名和想要预约的时间,然后提交表单。

```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约门票</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 50px;
        }
        form {
            max-width: 300px;
            margin: 0 auto;
        }
        label {
            display: block;
            margin: 10px 0 5px;
        }
        input[type="text"], input[type="datetime-local"] {
            width: 100%;
            padding: 8px;
            margin-bottom: 10px;
        }
        input[type="submit"] {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        input[type="submit"]:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <h1>预约门票</h1>
    <form id="reservationForm">
        <label for="name">姓名:</label>
        <input type="text" id="name" name="name" required>
        
        <label for="datetime">预约时间:</label>
        <input type="datetime-local" id="datetime" name="datetime" required>
        
        <input type="submit" value="提交预约">
    </form>
    <div id="confirmation"></div>

    <script>
        document.getElementById('reservationForm').addEventListener('submit', function(event) {
            event.preventDefault();
            
            const name = document.getElementById('name').value;
            const datetime = document.getElementById('datetime').value;
            
            fetch('http://localhost:3000/reserve', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ name, datetime })
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById('confirmation').innerText = `预约成功!确认码: ${data.confirmationCode}`;
            })
            .catch(error => {
                document.getElementById('confirmation').innerText = `预约失败: ${error}`;
            });
        });
    </script>
</body>
</html>

  • 16
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值