首页 > 代码库 > 【技术】Ajax $.get()
【技术】Ajax $.get()
HTML:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://www.mamicode.com/js/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function(){
$(document).on("click","#send",function(){
$.get("get1.php",{
username:$("#username").val(),
content:$("#content").val()
},function(result){
$("#content").val(result);
});
});
});
// $(function(){
// $("send").click(function(){
// $.get("get1.php",{
// username:$("#username").val(),
// content:$("#content").val()
// },function(data,textStatus){
// $("#resText").html(data);
// });
// });
// });
</script>
</head>
<body>
<form id="form1" action="#">
<p>
评论:
</p>
<p>
姓名:
<input type="text" name="username" id="username" />
</p>
<p>
内容:
<textarea name="content" id="content" rows="2" cols="20">
</textarea>
</p>
<p>
<input type="button" id="send" value="http://www.mamicode.com/提交" />
</p>
</form>
<div class="comment">
已有评论:
</div>
<div id="resText"></div>
</body>
</html>
get1.php:
<?php
//echo "123";
$username = $_GET[‘username‘];
if($username == "冰冰"){
echo "好人";
}else{
echo "坏人";
}
//$arr = array(‘title‘=>"2014排行榜",‘data‘=>array(‘id‘=>1,‘name‘=>‘要冰冰‘));
// echo json_encode($arr);
?>
【技术】Ajax $.get()