<!DOCTYPE html> <html lang="en"> <head> <Meta charset="UTF-8"> <title>ajax 验证</title> </head> <body> <Script type="text/javascript"> $(function(){ $('#send').click(function(){ var username = $("#username").val(); var content = $("#content").val(); $.ajax({ type:"post",url:"test.PHP",data:{username:username,content:content},dataType:"json",success:function(data){ $("#restext").empty(); $.each(data,function(commentIndex,comment){ html+='<div class="comment"><h6>'+comment['username']+':</h6><p class="para">'+comment['content']+'</p></div>'; }) $("#resText").html(html); } }) }); }); </Script> <form type="post" action="ajax01.html" > <input type="name" id="username" name="username"/> <div class="content"> fasafsafsafdsafdsafds </div> <button id="send">发送</button> </form> </body> </html>