可以定义AJAX(的WebMethod)的代码背后方法(添加System.Web.Services的引用)和使用$ .ajax或$ .post来请求它。看看我发布的代码片段供您参考。
Sample.aspx(联代码)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Services" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
[WebMethod]
public static string SendData(string sup,string qty)
{
return "OK : " + sup + " " + qty;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sample Page</title>
<script src="../script/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var sup1 = 10;
var qty1 = 20;
$("#btn1").click(function() {
var arg = '{sup: ' + sup1 + ',qty:' + qty1 + '}';
$.ajax({
type: "POST",
url: "Sample.aspx/SendData",
data: arg,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (msg) {
alert(msg.d);
},
error: function (msg) {
alert("Error: " + msg);
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btn1" value="Save" />
</div>
</form>
</body>
</html>
如果你想使用“RUNAT”属性,然后添加一个空的内部和客户端ID写属性。
<table runat="server" id="summ" width="350px" border="1" >
<tbody>
<tr></tr>
</tbody>
</table>
jQuery代码
$("#<%=summ.ClientID%> > tbody:last").append('<tr><td><input type="button" id="delete" value="Delete"></td><td>' + sup1 + '</td><td>' + qty1 + '</td><td><input type="text"></td></tr>');
OR
您想发表什么细胞的价值?这些** sup **和** qty **?使用$ .post来请求和发送数据。 – adatapost 2012-01-02 02:52:39
@AVD是的,这些变量。我能访问后面的代码吗?对不起,我对JavaScript很陌生。 – 2012-01-02 03:02:04
我发布的样本可能会帮助你。发布相关代码,如果有问题。 – adatapost 2012-01-02 03:40:33