• 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;  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>
    View Code
     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 = "<p>姓名: "+userName+"<br/>内容: "+content+"</p>";
    11             Response.Write(backContent);
    12         }
    13     }
    View Code

    效果图:

  • 相关阅读:
    Python 第一课
    HTML学习--基础(2)
    HTML学习--初探(1)
    设计模式--观察者模式
    设计模式--迭代器模式
    设计模式--装饰器模式
    maven常用依赖总结
    mybatis学习二
    mybatis学习一
    maven新建项目的几种方式和启动
  • 原文地址:https://www.cnblogs.com/hshuai/p/4272119.html
Copyright © 2020-2023  润新知