1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<?
php
header('Content-Type:text/html;
charset
=
utf
-8');
?>
<
script
type
=
"text/javascript"
>
$(function() {
$("#subbtn").click(function() {
var params = $('input').serialize();
var url = "你的服务器端 php";
$.ajax({
type: "post",
url: url,
dataType: "json",
data: params,
success: function(msg){
var tishi = "您提交的姓名为:" + msg.name +
"<
br
/> 您提交的密码为:" + msg.password;
$("#tishi").html(tishi);
$("#tishi").css({color: "green"});
}
});
});
});
</
script
>
<
p
><
label
for
=
"name"
>姓名:</
label
>
<
input
id
=
"name"
name
=
"name"
type
=
"text"
/>
</
p
>
<
p
><
label
for
=
"password"
>密码:</
label
>
<
input
id
=
"password"
name
=
"password"
type
=
"password"
/>
</
p
>
<
span
id
=
"tishi"
></
span
>
<
p
><
input
id
=
"subbtn"
type
=
"button"
value
=
"ajax 测试"
/></
p
>
|
服务器 PHP 代码如下
1
2
3
|
<?php
echo
json_encode(
$_POST
);
|