客户端的代码
send.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="http://127.0.0.1/jquery-3.3.1.js"></script>
<script>
function Ajax(){
$.get("receive.php",
{user:$("#user").val(),comment:$("#comment").val()},
function(data){
$("#target").append(data);
});
};
</script>
<p>user:<input id="user" type="text"></p>
<p>comment<textarea id="comment" name="" cols="20" rows="2"></textarea></p>
<input type="button" value="Ajax submit" onclick="Ajax()">
<div id="target"></div>
</body>
</html>
receive.php
<?php
header("Content-type:text/html;charset=utf-8");
$user = $_GET['user'];
$comment = $_GET['comment'];
echo "<h3>user:" . $user . "</h3>";
echo "<p>comment:" . $comment . "</p>";
?>
客户端发送数据后,我打开127.0.0.1/receive.php
显示结果是
user:
comment:
为何不是:
user:john
comment:1234
可以啊