jQuery exercise t322, from 0 to 1

getData.php

<?php

$name = $_POST['name'];
$age = $_POST["age"];

echo "<p>姓名: $name <br> 年龄: $age </p>";

?>


t322.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/jquery-3.5.1.js"></script>
    <script>
        //load方法
        //回调函数
        $(function () {
           $("div").load("getData.php",{
               name : "tom",
               age : 24
           },function (reponse, status, xhr) {
               var $div2 = $("<div style='border: 1px solid #666666;'></div>");
               var str = "";
               str += "reponse :" + reponse + "<br>";
               str += "status: " + status + "<br>";
               str += "xhr: " + xhr + "<br>";
               $div2.html(str);
               $("div").append($div2);
           })
        });
        /*
        该回调函数有3个参数:reponse,status,xhr。
        其中,replose表示请求后返回的内容,
        status表示请求状态,
        xhr表示XMLHttpRequest对象。


        有几点要特别说明
        在load方法中,无论Ajax请求是否成功,只要请求完成complete,
        回调函数fn都会被触发。
        load方法一般只会用到参数1,很少会用参数2和参数3.
        load方法一般是用来向服务器请求静态的数据文件。

         */
    </script>
</head>
<body>
    <div></div>
</body>
</html>

 

Guess you like

Origin blog.csdn.net/modern358/article/details/113842711