Ajax提出フォームインスタンス

3880 ワード

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" src = "http://code.jquery.com/jquery.min.js" ></ script > < 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 );