weixin_33708432 2015-03-19 12:15 采纳率: 0%
浏览 20

始终返回零值[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call" dir="ltr">How do I return the response from an asynchronous call?</a>
                            <span class="question-originals-answer-count">
                                (38 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2015-03-19 12:18:58Z" class="relativetime">5 years ago</span>.</div>
        </div>
    </aside>
function getvalue(value) {
        document.getElementById('<%= hdnPack.ClientID %>').value = "0";
        var stdPack = 0;
        alert("a");
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "test.aspx/GetStdSellingPack",
            data: "{'Col1':'" + value+ "'}",
            dataType: "json",
            success: function (data) {
                alert("b");
                if (data != null) {

                    $(data).each(function () {
                        var values = data.d;
                        stdPack = values;
                    });
                }
            },
            error: function (result) {
                alert("Error");
            }
        });
        alert("c");
        return stdPack;

    }

Am trying to execute this function Always returning zero , Actually what happening Alert(a) got Fired ,Then Alert (C) fired And Suddenly it goes to Alert(b). The result I would like to get In order, Alert(a) to execute first then Alert(b) followed by alert(c).Pl give me a solution .Thanks in Advance

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33709219 2015-03-19 12:18
    关注

    ajax is asynchronous, so it can't guaranty the sequence of code executed. To return a value from function having ajax call check this link

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度