$.get()

<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>$.get()方法</title>
<script src="../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="提交" id="send"/></p>
</form>
<div class="comment">已有评论
<div id="resText"></div>
</div>
</div>

<script type="text/javascript">

//方法1
$("#send").click(function() {
$.get('get.php', {
username:$("#username").val(),
content:$("#content").val()
},function(data,textStatus) {
alert(data);
$("#resText").append(data);
});
});

//方法2

$("#send").click(function() {

  $("#resText").load("get.php ? username="+$('#username').val()+"&content="+$(‘#content’).val());

});

//方法3

$("#send").click(function() {
  $("#resText").load('get.php', {
    username:$("#username").val(),
    content:$("#content").val()
  })
});
</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>";
?>

posted @ 2017-04-18 13:33  代码小精灵  阅读(566)  评论(0编辑  收藏  举报