繁体   English   中英

JQuery Ajax方法成功时未调用JQuery函数

[英]JQuery function is not calling when JQuery Ajax method succeed

嗨,我正在使用JQuery在asp.net中做一个小型应用程序

    $(document).ready(function() {
        var imgPoll = new Image();
        imgPoll.src = 'images/red-bar.png';
        if ($("#divVoted").length > 0) //Already voted
        {
            animateResults();
        }
        else {
            $("#rdoPoll0").attr("checked", "checked"); //default select the first Choice

            $("#btnSubmit").click(function() {
                $("#divPoll").css("cursor", "wait"); //show wait cursor inside Poll div while processing
                $("#btnSubmit").attr("disabled", "true") //disable the Vote button while processing
                var pID = $("input[id$=hidPollID]").val(); //get Poll ID
                var cID = $("input[name='rdoPoll']:checked").val(); //get the checked Choice
                var data = "{'pID':'" + pID + "', 'cID':'" + cID + "'}"; //create the JSON data to send to server
                jQuery.ajax(
            {

                type: 'POST',

                data: data,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                url: 'Poll_CS.aspx/UpdatePollCount',
                success: function(msg)  //show the result
                {
                    //alert("valid");
                    $("#divPoll").css("cursor", "default"); //remove the wait cursor
                    $("#btnSubmit").attr("disabled", "false") //enable the Vote button
                    $("div[id$=divAnswers]").fadeOut("fast").html(msg.d).fadeIn("fast",               function() { animateResults(); });
                }
            });
            });
        }
        function animateResults() {

            $("div[id$=divAnswers] img").each(function() {
                var percentage = $(this).attr("val");
                $(this).css({ width: "0%" }).animate({ width: percentage }, 'slow');
            });
        }
    });

在Jquery.ajax方法成功之后,不会调用animateResults()函数。 在本地服务器中,它运行良好,而在主机服务器中,则无法运行。

请提出解决此问题的建议

感谢Ganesh

在jQuery .ready()外部定义函数。 不知道为什么,但这可能会导致您的问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM