<Ajax> 三. 前端和后端通过表单数据交互

<!-- 前端代码 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!-- 表单提交数据 -->
<form action="./getData.php" method="get">
    <input type="text" placeholder="请输入你喜欢的英雄" name="name">
    <input type="text" placeholder="请输入英雄位置" name="position">

    <!-- 提交按钮 -->
    <button type="submit">提交</button>
</form>
</body>
</html>
<!-- 后端代码 -->
<?php
    /**
     * 前后端数据交互过程
     * 前端:
     * 1. 让用户输入内容
     * 2. 点击提交
     * 
     * 后端:
     * 1. 接收数据
     * 2. 查询数据
     * 3. 结果页面
     */

    // 返回结果
    print_r($_GET);
    echo '<br>';
    echo $_GET['name'];
    echo '<br>';
    echo $_GET['position'];
?>

 

posted @ 2018-01-20 17:50  云淡风轻我爱编程  阅读(1003)  评论(0编辑  收藏  举报