Prototype更新数据不刷新实例
Prototype更新数据不刷新实例,简单用实例说明prototype在ajax中的应用。
Prototype ajax参数请见:Prototype.js 1.4中文使用手册PDF版下载
default.aspx源码
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">3
<html xmlns="http://www.w3.org/1999/xhtml" >4
<head runat="server">5
<title>无标题页</title>6
<style type="text/css">7

*
{8

9
margin:0;10

11
padding:0;12

13
font-family: verdana, "ms song", 宋体,sans-serif; 14

15
color: #494949; 16

17
font-size: 12px;18

19
line-height: 1.5em;20

21
}22

23
#diggs24


{25
border-right: fuchsia 1px solid;26
border-top: fuchsia 1px solid;27
border-left: fuchsia 1px solid;28
width: 50px;29
border-bottom: fuchsia 1px solid;30
height: 50px;margin-left:100px;margin-top:100px;text-align: center;31
}32

#digg_num_42374
{border-top: fuchsia 1px solid; width: 50px;height: 15px;}33
</style>34
<script language="JavaScript" type="text/javascript" src="JS/Prototype.js"></script>35
<script language="JavaScript" type="text/javascript"> 36
function DiggNews(nid)37

{38

var options=
{ 39
method:'get', 40
parameters:"Action=newsDiggs&nid="+nid, 41
onComplete:function()42

{ 43
document.getElementById("digg_num_42374").innerHTML="已推荐"; 44
} 45
}; 46
new Ajax.Request('Default.aspx?no-cache='+Math.random(),options);47
}48

49
</script>50
</head>51
<body>52
<form id="form1" runat="server">53
54
<div id="diggs"><span class="diggnum" >2</span>55
<div id="digg_num_42374" onclick="DiggNews(26)">推荐</div>56
</div>57
</form>58
</body>59
</html>60

default.aspx.cs源码
1
using System;2
using System.Data;3
using System.Configuration;4
using System.Collections;5
using System.Web;6
using System.Web.Security;7
using System.Web.UI;8
using System.Web.UI.WebControls;9
using System.Web.UI.WebControls.WebParts;10
using System.Web.UI.HtmlControls;11

12
public partial class _Default : System.Web.UI.Page13


{14
protected void Page_Load(object sender, EventArgs e)15

{16
Response.CacheControl = "no-cache";17
string Action = Request.QueryString["Action"];18
int nid = 0;19
if (Request.QueryString["nid"] != null)20

{21
nid = int.Parse(Request.QueryString["nid"].ToString());22
}23
24
switch (Action)25

{26
27
case "newsDiggs":28
getCopyRight(nid);29
break;30
31
32
}33
}34
protected void getCopyRight(int nid)35

{36
string strsql = "update help set orderid =orderid+1 where id ="+nid;37
Help.SQLServerDAL.SqlHelper.ExecuteNonQuery(CommandType.Text, strsql, null);38
Response.End();39
}40
41
}42

浙公网安备 33010602011771号