20 เมษายน 2554

การส่งค่าโดย Ajax ของ Jquery

--------------------------------------------------------------------------------------------------------------

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function(){

        $('#button').click(function(){          
                $.ajax({
                  type: 'POST',
                  url: "test.php",
                  data: {name: $('#name').val()},
                  success: function(data){
                     $('#result').html( data );                  
                  }
                
                });              
        })
      
    });
</script>
</head>
<body>

<input type="text" name="name" id="name" />
<input type="submit" name="button" id="button" value="Submit"/>
<br />
<span id="result"></span>

</body>
</html>

 --------------------------------------------------------------------------------------------------------------
ไฟล์  test.php

<?php
    echo $_POST['name'];
?>

ไม่มีความคิดเห็น:

แสดงความคิดเห็น