php 使用jquery实现ajax

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" SRC="jquery.js"></script>
<script>
function send1(){
     var my_data= document.getElementById("name").value;
     $.ajax({
         url: "jquery_ajax.php",  
         type: "POST",
         data:{'name':my_data},
         //dataType: "json",
         error: function(){  
             alert('Error loading XML document');  
         },  
         success: function(data){//如果调用php成功    
             document.getElementById("div").innerHTML= data;
         }
     });
     
 }
</script>
</head>

<body>
    <input type="text" id="name" value="无忧之路"><br>
    <input type="button" onclick="send1();" value="请输入你的名字"><br>
    <div id="div"></div>
</body>
</html>

php部分:

<?php
    $name = $_POST['name'];
    echo "hello, $name!";
?>

posted @ 2013-10-22 13:09  无忧之路  阅读(397)  评论(0编辑  收藏  举报
无忧之路