0
<html>
<head>
<meta charset="utf-8" />
<title>jQuery Ajax - POST</title>
<script type="text/javascript" src="jquery_1.6.1.js"></script>
<script type="text/javascript"><!--
$(document).ready(function() {
  $('form').submit(function() {
    var data = 'name='+$('#nm').val();
    var data = 'name='+$('#sn').val();
    $.post('script.php', data, function(response){
      $('#dv').html(response);
      $('#dv2').html(response);
    });

    return false;      // required to not open the page when form is submited
  });
});
--></script>
</head>
<body>
<div id="dv">Here will be displayed the response.</div><br />
<form action="script.php" method="post">
 Name: <input type="text" name="nm" id="nm" /><br />
<div id="dv2">Here will be displayed the 2nd response.</div><br />
 Second name: <input type="text" name="sn" id="sn" /><br />
 <input type="submit" value="Submit" />
</form>
</body>
</html>

Name を JavaScript に投稿して divtag (dv) の下に出力し、2 番目の名前を (dv2) に出力する必要があります。

4

1 に答える 1