php安装,背景处置惩罚脚本语言。
后端开发语言不能直接允许,必须放在服务器对对应的文件夹下运行。
如:wamp的对应服务器的文件夹是www
get请求
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>02-get</title>
- </head>
- <body>
- <form action="02-get.php" method="get">
- <input type="text" name="userName"><br>
- <input type="password" name="userPwd"><br>
- <input type="submit" value="提交"><br>
- </form>
- </body>
- </html>
复制代码- <?php
- //print_r($_GET);//查看可以知道这回得到一个Array的数据
- echo $_GET["userName"];
- echo $_GET["userPwd"];
- ?>
复制代码
post
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>02-post</title>
- </head>
- <body>
- <form action="02-post.php" method="post">
- <input type="text" name="userName"><br>
- <input type="password" name="userPwd"><br>
- <input type="submit" value="提交"><br>
- </form>
- </body>
- </html>
复制代码- <?php
- //print_r($_GET);//查看可以知道这回得到一个Array的数据
- echo $_POST["userName"];
- echo $_POST["userPwd"];
- ?>
复制代码
get和post的异同点
ajax
原生步调
- 创建异步对象
- 设置请求方式和请求地址
- 发送请求
- 监听状态变革
- 处置惩罚返回的效果
代码及征象:
- //4.监听状态的变化,状态变化都会执行
- xmlhttp.onreadystatechange = function () {
- }
复制代码
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>04-ajax-get</title>
- <!--
- 1.什么是Ajax
- -->
- <script >
- window.onload = function () {
- var oBtn= document.querySelector("button");
- oBtn.onclick = function (evl) {
- //1.需要创建异步对象
- var xmlhttp = new XMLHttpRequest();
- //2.设置请求方式和请求地址
- xmlhttp.open("GET","04-ajax-get.php",true);
- //3.发生请求
- xmlhttp.send();
- //4.监听状态的变化,状态变化都会执行
- xmlhttp.onreadystatechange = function () {
- if(xmlhttp.readyState === 4){
- //判断是否请求成功
- if(xmlhttp.status >= 200 && xmlhttp.status < 300 ||
- xmlhttp.status === 304){
- //5.处理返回的结果
- console.log("接收到服务器返回的数据");
- }
- else {
- //5.处理返回的结果
- console.log("没有接收到服务器返回的数据");
- }
- }
- }
- }
- }
- </script>
- </head>
- <body>
- <button>发生请求</button>
- </body>
- </html>
复制代码- <?php
- echo "ajax get test"
- ?>
复制代码
完整步调代码及效果:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>04-ajax-get</title>
- <!--
- 1.什么是Ajax
- -->
- <script >
- window.onload = function () {
- var oBtn= document.querySelector("button");
- oBtn.onclick = function (evl) {
- //1.需要创建异步对象
- var xmlhttp = new XMLHttpRequest();
- //2.设置请求方式和请求地址
- xmlhttp.open("GET","04-ajax-get.php",true);
- //3.发生请求
- xmlhttp.send();
- //4.监听状态的变化,状态变化都会执行
- xmlhttp.onreadystatechange = function () {
- if(xmlhttp.readyState === 4){
- //判断是否请求成功
- if(xmlhttp.status >= 200 && xmlhttp.status < 300 ||
- xmlhttp.status === 304){
- //5.处理返回的结果
- //console.log("接收到服务器返回的数据");
- alert(xmlhttp.responseText);
- }
- else {
- //5.处理返回的结果
- //console.log("没有接收到服务器返回的数据");
- }
- }
- }
- }
- }
- </script>
- </head>
- <body>
- <button>发生请求</button>
- </body>
- </html>
复制代码- <?php
- echo "ajax get test"
- ?>
复制代码
jquery步调
优点
小写也可正常发送
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |