码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET的Ajax异步传值尝试

时间:2014-06-12 17:15:51      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

bubuko.com,布布扣
 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>
bubuko.com,布布扣
bubuko.com,布布扣
 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 }
bubuko.com,布布扣

 

ASP.NET的Ajax异步传值尝试,布布扣,bubuko.com

ASP.NET的Ajax异步传值尝试

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/hellowzl/p/3781824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!