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!"; ?>
本文出自 无忧之路 - 博客园