=波波日志 > Asp.Net/C#/WCF > ajaxpro ajaxmethod 重载调用问题=
ajaxpro ajaxmethod 重载调用问题
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 ajaxmethod 重载调用问题
使用ajapro时,ajaxmethod最好不好有重载版本,要不由于js变量的非强类型性,导致调用重载版本时会出现调用不到对应版本的函数,或者出现错误,即使传递了回调函数也会出现同步执行等问题。
下面是测试代码
第一,多个参数的重载,调用到不同的函数或者发生错误,异步转变为同步
+展开
-C#
/// <summary>
/// 无参数返回值为string
/// </summary>
/// <returns></returns>
//[AjaxPro.AjaxMethod]
public string Now()
{
return DateTime.Now.ToString()+"--Params0";
}
/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other)
{
return DateTime.Now.ToString() + "--" + other;
}/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other,string other1)
{
return DateTime.Now.ToString() + "--" + other+"--"+other1;
}
/// 无参数返回值为string
/// </summary>
/// <returns></returns>
//[AjaxPro.AjaxMethod]
public string Now()
{
return DateTime.Now.ToString()+"--Params0";
}
/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other)
{
return DateTime.Now.ToString() + "--" + other;
}/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other,string other1)
{
return DateTime.Now.ToString() + "--" + other+"--"+other1;
}
+展开
-JavaScript
function callback(r){alert('回调:'+r.value);}
alert(className.Now(callback).value);//虽然传递了回调函数,但是实际是同步执行。输出null,因为发生错误,r.error = {"Message":"类型“System.DBNull”的对象无法转换为类型“System.String”。","Type":"System.ArgumentException"
alert(className.Now('客户端发送的其他内容1', callback).value);//虽然传递了回调,但是还是同步的,没有执行回调函数的输出。只要一次输出“回调:服务器时间+客户端发送的其他内容1”
alert(className.Now('客户端发送的其他内容1', '客户端发送的其他内容2', callback, tp));//异步执行,先输出null【注意这里没有调用value属性,因为异步执行,所以ajaxpro包装的对象会为null,这样对null获取value属性会出错】,后面输出“回调:服务器时间+客户端发送的其他内容1”,忽略了参数“客户端发送的其他内容2”。
alert(className.Now(callback).value);//虽然传递了回调函数,但是实际是同步执行。输出null,因为发生错误,r.error = {"Message":"类型“System.DBNull”的对象无法转换为类型“System.String”。","Type":"System.ArgumentException"
alert(className.Now('客户端发送的其他内容1', callback).value);//虽然传递了回调,但是还是同步的,没有执行回调函数的输出。只要一次输出“回调:服务器时间+客户端发送的其他内容1”
alert(className.Now('客户端发送的其他内容1', '客户端发送的其他内容2', callback, tp));//异步执行,先输出null【注意这里没有调用value属性,因为异步执行,所以ajaxpro包装的对象会为null,这样对null获取value属性会出错】,后面输出“回调:服务器时间+客户端发送的其他内容1”,忽略了参数“客户端发送的其他内容2”。
第二,参数类型不一样的重载版本,会出现错误。
+展开
-C#
/// <summary>
/// 参数为int
/// </summary>
/// <param name="i">其他字符参数</param>
/// <returns></returns>
//[AjaxPro.AjaxMethod]
public string Now(int i)
{
return DateTime.Now.ToString() + "--" + i.ToString();
}
/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other)
{
return DateTime.Now.ToString() + "--" + other;
}
/// 参数为int
/// </summary>
/// <param name="i">其他字符参数</param>
/// <returns></returns>
//[AjaxPro.AjaxMethod]
public string Now(int i)
{
return DateTime.Now.ToString() + "--" + i.ToString();
}
/// <summary>
/// 带一个参数返回值为string
/// </summary>
/// <param name="other">其他字符参数</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public string Now(string other)
{
return DateTime.Now.ToString() + "--" + other;
}
+展开
-JavaScript
function callback(r){alert('回调:'+r.value);}
className.Now(1,callback);//输出null,因为发生错误, r.error = {"Message":"类型“System.Int64”的对象无法转换为类型“System.String”。","Type":"System.ArgumentException"
className.Now('客户端发送的其他内容1', callback);//正常调用,输出“回调:服务器时间+客户端发送的其他内容1”
className.Now(1,callback);//输出null,因为发生错误, r.error = {"Message":"类型“System.Int64”的对象无法转换为类型“System.String”。","Type":"System.ArgumentException"
className.Now('客户端发送的其他内容1', callback);//正常调用,输出“回调:服务器时间+客户端发送的其他内容1”
通过上面的示例说明,最好不要有重载版本的ajaxmethod。
类别:Asp.Net/C#/WCF 作者:波波 日期:2010-12-23 【评论:0】
相关文章
- ·ajaxpro方法ajaxmethod调用示例
- ·ajaxpro综合示例-ajaxpro无刷新更新gridview数据
- ·ajaxpro使用总结--总目录
- ·ajaxpro返回值类型总结-string,int
- ·ajaxpro返回值类型总结-DataTable
- ·ajaxpro返回值类型总结-DataSet
- ·ajaxPro7.7.31.1返回DataTable,DateSet出错
- ·ajaxPro7.7.31.1 出现this.onTimeout is not a function 的Bug解决方案
- ·VBScript如何调用异步调用ajaxpro注册的方法
- ·ASP调用C#编写的DLL组件问题
- ·jQuery通过调用webservice返回json数据的问题
- ·客户端VBScript和JavaScript相互调用的问题
暂时没有评论!
发表留言
热门博文
- 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#如何设置标记方法等为否决的不可用
随机博文
广告商赞助

