首页 > 代码库 > $.get()
$.get()
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>$.get()方法</title>
<script src="http://www.mamicode.com/scripts/jquery-1.3.1.js" type="text/javascript"></script>
<style type="text/css">
.container{
width: 60%;
margin: 0 auto;
border:1px solid #666;
}
.comment{
background-color: #cfcfcf;
}
</style>
</head>
<body>
<div class="container">
<form action="#" id="form1">
<p>评语:</p>
<p>姓名:<input type="text" name="username" id="username"/></p>
<p>内容:<input type="text" name="content" id="content"/></p>
<p><input type="button" value="http://www.mamicode.com/提交" id="send"/></p>
</form>
<div class="comment">已有评论
<div id="resText"></div>
</div>
</div>
<script type="text/javascript">
$("#send").click(function() {
$.get(‘get.php‘, {
username:$("#username").val(),
content:$("#content").val()
},function(data,textStatus) {
alert(data);
$("#resText").append(data);
});
});
</script>
</body>
</html>
//要加载的get.php文档,代码如下
<?php
header("Content-Type:text/html; charset=utf-8");
echo "<div class=‘comment‘><h6>{$_GET[‘username‘]}</h6><p class=‘para‘>{$_GET[‘content‘]}</p></div>";
?>
$.get()