ajaxpro返回值类型总结-string,int
ajaxpro使用总结系列其他内容
ajaxpro综合示例-ajaxpro无刷新更新gridview数据
ajaxPro7.7.31.1 出现this.onTimeout is not a function 的Bug解决方案
ajaxPro7.7.31.1 返回DataTable,DateSet出错
ajaxpro无刷新,分页更新repeater/GridView数据源
ajaxpro返回值类型总结-string,int
返回string或者int都一样,只需要取ajaxpro包装好的对象value就行。测试代码如下
ajaxproStringInt.aspx
+展开
-HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajaxprostringint.aspx.cs" Inherits="ajaxproStringInt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>ajaxpro返回值类型总结-string</title>
</head>
<body>
<script type="text/javascript">
function callback(r) {
var tp = typeof r.context == 'number' ? r.context : r.context.tp;
switch (r.context) {
case 1: alert('服务器返回的时间为:' + r.value); break;
default: alert(r.context.a + '+' + r.context.b + '=' + r.value); break;
}
}
function callServer(tp) {
switch (tp) {//在调用方法的同时传递tp参数,以便在回调函数中通过context属性获取到
case 1: ajaxproStringInt.Now('客户端发送的其他内容1', callback, tp); break;
default: ajaxproStringInt.Add(7, 8, callback, { tp: tp, a: 7, b: 8 }); break; //给context传递json对象就可以同时传递多种数据了
}
}
</script>
<form id="form1" runat="server"><input type="button" value="调用Now" onclick="callServer(1)" />
<br ><input type="button" value="调用Add" onclick="callServer(2)" /></form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>ajaxpro返回值类型总结-string</title>
</head>
<body>
<script type="text/javascript">
function callback(r) {
var tp = typeof r.context == 'number' ? r.context : r.context.tp;
switch (r.context) {
case 1: alert('服务器返回的时间为:' + r.value); break;
default: alert(r.context.a + '+' + r.context.b + '=' + r.value); break;
}
}
function callServer(tp) {
switch (tp) {//在调用方法的同时传递tp参数,以便在回调函数中通过context属性获取到
case 1: ajaxproStringInt.Now('客户端发送的其他内容1', callback, tp); break;
default: ajaxproStringInt.Add(7, 8, callback, { tp: tp, a: 7, b: 8 }); break; //给context传递json对象就可以同时传递多种数据了
}
}
</script>
<form id="form1" runat="server"><input type="button" value="调用Now" onclick="callServer(1)" />
<br ><input type="button" value="调用Add" onclick="callServer(2)" /></form>
</body>
</html>
ajaxproStringInt.aspx.cs
+展开
-C#
using System;
public partial class ajaxproStringInt : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxproStringInt));
}
/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other)
{
return DateTime.Now.ToString() + "--" + other;
}
/// <summary>
/// 返回值为int的方法
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public int Add(int a, int b)
{
return a + b;
}
}
public partial class ajaxproStringInt : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxproStringInt));
}
/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other)
{
return DateTime.Now.ToString() + "--" + other;
}
/// <summary>
/// 返回值为int的方法
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public int Add(int a, int b)
{
return a + b;
}
}
加支付宝好友偷能量挖...
原创文章,转载请注明出处:ajaxpro返回值类型总结-string,int