前端之家收集整理的这篇文章主要介绍了
ajax 验证 简单例子,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<!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>