ASP.NET的Ajax异步传值尝试

 1 前台代码:
 2 <head runat="server">
 3     <title>无标题页</title>
 4     <script src="JavaScript/jquery-1.4.2.min.js" type="text/javascript"></script>
 5     <script type="text/javascript" language="javascript">
 6         //Ajax传值
 7         function startClick() {
 8             var str="123";
 9             $.ajax({
10                 url: Default.aspx?time= + (new Date().toTimeString()),
11                 type: get,
12                 data: {
13                     Type: str
14                 },
15                 success: function(data) {
16                     if (data != null) {
17                         if (data == "1") {
18                             $("#serverName").text("成功!");
19                             setTimeout("closeHide()", 3000)  //单位毫秒
20                         }
21                         else {
22                             $("#serverName").text("失败!");
23                             setTimeout("closeHide()", 3000)  //单位毫秒
24                         }
25                     }
26                 }
27             });
28         }
29         //隐藏控件
30         function closeHide() {
31             $("#divHide").hide();
32         };
33     </script>
34 </head>
35 <body>
36     <form id="form1" runat="server">
37     <div>
38         <asp:Button ID="divHide" runat="server" Text="显示" onclick="bt_Click" />
39     </div>
40     <div>
41         <div id="serverName" >ticketApps</div>
42         <input type="button" id="btnStart" value="重启" onclick="startClick()"/>
43     </div>
44     </form>
45 </body>
46 </html>
 1 后台代码:
 2 protected void Page_Load(object sender, EventArgs e)
 3 {
 4     //ajax请求
 5     if (!string.IsNullOrEmpty(Request["Type"]))
 6     {
 7         Response.Write(startServer(Request["Type"]));
 8         Response.End();
 9     }
10 }
11 /// <summary>
12 /// Ajax程序
13 /// </summary>
14 /// <param name="s">程序代码</param>
15 /// <returns>0:重启失败 1:重启成功</returns>
16 public string startServer(string s)
17 {
18     string re = string.Empty;
19     string aCode=string.Empty;
20     try
21     {
22         aCode = s;
23         re = "1";
24     }
25     catch
26     {
27         re = "0";
28     }
29     return re;
30 }

 

ASP.NET的Ajax异步传值尝试,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。