ajax学习笔记(3)--$.get()方法
1 <head runat="server"> 2 <title>jQuery中的$.get()方法title> 3 <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript">script> 4 <script type="text/javascript"> 5 $(function () { 6 $("#send").click(function () { 7 $.get( 8 "get.aspx", //url 9 {username: $("#username").val(), 10 content: $("#content").val() 11 }, //data 12 function (data, textStatus) { 13 $("#resText").html(data); 14 15 } //回调函数 16 ) 17 }); 18 }); 19 script> 20 head> 21 <body> 22 <form id="form1" runat="server" style="border: 1px solid grey; width: 300px;"> 23 <div> 24 <p> 25 评论:p> 26 <p> 27 姓名:<input type="text" name="username" id="username" />p> 28 <p> 29 内容:<textarea name="content" id="content" rows="2" cols="20">textarea>p> 30 <p> 31 <input type="button" id="send" value="提交" />p> 32 div> 33 <div class="comment"> 34 已有评论: 35 <div id="resText"> 36 div> 37 div> 38 form> 39 body>
1 public partial class get : System.Web.UI.Page 2 { 3 protected void Page_Load(object sender, EventArgs e) 4 { 5 string userName=Request.QueryString["username"]; 6 string content = Request.QueryString["content"]; 7 8 //服务器返回内容的格式:html,xml,script,json,text,和_default 9 //这里使用的是html格式 10 string backContent = "姓名:
"+userName+"
内容: "+content+""; 11 Response.Write(backContent); 12 } 13 }
效果图: