【问题标题】:Calling a ASP.net WebMethod from the success function of another WebMethod从另一个 WebMethod 的成功函数调用 ASP.net WebMethod
【发布时间】:2017-04-24 09:57:49
【问题描述】:

一段时间以来,我一直在努力寻找解决此问题的方法,如果您能提供任何帮助,我将不胜感激。我不是在寻找使用 Ajax 的答案。谢谢。

我遇到的情况是我需要调用一个返回整数的 WebMethod。然后在确认消息中向用户显示该整数。如果他们确认,那么我需要调用第二个 WebMethod,然后通过警报消息提醒他们结果。

当我这样做时,除了第二个成功功能外,一切正常。永远不会达到该功能,因此永远不会提醒用户。

这是我的情况的示例 JavaScript:

$( "a" ).live( "click", function() {
    PageMethod.GetCount(OnSucceed, OnFail);
});

OnSucceed(result)
{
    var retVal = Confirm(result);

    if(retVal == false)
        return false;

    PageMethod.Create(Succ, OnFail); //Produces the correct files
}

function Succ(resultStr)
{
    alert(resultStr); //This is never reached
}

function OnFail(error)
{
    alert(error);
}

【问题讨论】:

    标签: javascript c# asp.net web-services


    【解决方案1】:
    Try Closure :
    $( "a" ).live( "click", function() {
        PageMethod.GetCount(OnSucceed, OnFail);
    });
    
    OnSucceed(result)
    {
        var retVal = Confirm(result);
    
        if(retVal == false)
            return false;
    
        PageMethod.Create(function(response) { 
         alert(response); 
        }, OnFail); //Produces the correct files
    }
    
    function OnFail(error)
    {
        alert(error);
    }
    

    【讨论】:

    • 我试过了,不幸的是仍然没有达到警报。不过谢谢!
    猜你喜欢
    • 2015-11-18
    • 2013-06-06
    • 2015-11-26
    • 2011-10-03
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多