=波波日志 > Asp.Net/C#/WCF > ajaxpro返回值类型总结-string,int=
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;
}
}
类别:Asp.Net/C#/WCF 作者:波波 日期:2010-12-23 【评论:0】
相关文章
暂时没有评论!
发表留言
热门博文
- IE里Cookie跨域不能读取
- web服务因URL意外地以/**结束,请求格式无法识别
- 去掉隐藏asp.net编译出错aspxerrorpath错误参数
- 解决asp.net验证视图状态 MAC 失败
- 找不到System.Web.Script.Services.ScriptService
- 在aspx,ashx页面挂起线程执行
最新博文
- WCF利用限流(Throttling)控制并发访问[下篇]
- WCF利用限流(Throttling)控制并发访问[上篇]
- ConcurrencyMode.Multiple模式下的WCF服务同步上下文对并发的影响[下篇]
- ConcurrencyMode.Multiple模式下的WCF服务同步上下文对并发的影响[上篇]
- WCF基于ConcurrencyMode.Reentrant模式下的并发控制机制
- C#如何设置标记方法等为否决的不可用
随机博文
- C# 设置数据库连接运行时超时时间
- ASP.NET 2.0移动开发之定义设备筛选器(2)
- 11.6 用户控件和自定义控件--小结
- C# 3.0 OR工具介绍
- C#通过Html Agility Pack解析HTML
- WCF服务代理不及时关闭会有什么后果
广告商赞助

