日期:2014-05-18  浏览次数:20402 次

ajaxpro的一个问题,关于连续两次用js调用后台函数失败。请高手解答
假设server端类ajaxtest.test有ajax方法:
[AjaxMethod]
public   string   GetText1()
{
        return   "ab ";
}
[AjaxMethod]
public   string   GetText2()
{
        return   "cd ";
}
client端有方法:
//调用后台函数
function   test1()
{
      ajaxtest.test.GetText1(test1_callback);
}
//相应回调
function   test1_callback(response)
{
        alert(response.value);
        ajaxtest.test.GetText2(test2_callback);
}
function   test2_callback(response)
{
        alert(response.value);

}

/////////////////////
结果是第一个调用成功返回。alert出ab
但调用第二个server端函数的时候就失败了。
抓包发现,第二次服务器端请求的时候就abort了!
//
小弟实在才疏学浅啊,   看了些介绍ajaxpro的东西,也没找出个为什么。
希望高手能赐教一下。啊

------解决方案--------------------
我测试过你的代码,是可以正常运行的,因为我无法给出建设性等价建议了

也许,超时,也许,防火墙,阻止,

我只碰到过这两种情况

另外,AjaxPro 中最佳的访问方式,访问 value 之前应该检查是发生错误,大概应该这样:

》》》

function test2_callback(response)
{
if(response.error) { // checks if some error occurs
alert( "发生错误: " + response.error.Message + "\n堆栈信息: " + response.error.Stack);
return;
}
// common behavior
// ...
alert(response.value);
}



------解决方案--------------------

可能你的服务器有问题,导致嵌套的异步处理方式发生错误


刚刚写了篇文章,有助于你高效寻找错误信息,有兴趣可以看看,

一种简单实用的 AjaxPro 错误处理方式
http://www.cnblogs.com/Jinglecat/archive/2007/07/14/817812.html