2

此函数用于点击页面加载,现在第一个警报显示,但 ajax 调用内部的那个不显示。这似乎根本没有达到 ajax 调用。它应该在我的控制器中调用一个方法,但似乎不再命中它。

 $(function () {
        $(document).ready(function () {
            alert("2");
            $.ajax({
                url: 'CallCenter/CallCenterAmt',
                type: 'Post',
                contentType: 'application/json;',
                async: false,
                success: function (data) {
                    alert(data);
                    if (data == 2) {
                        document.getElementById("First").style.display = 'Inline';
                        document.getElementById("Second").style.display = "Inline";
                        document.getElementById("Third").style.visibility = "Hidden";
                    }
                    else if (data == 3) {
                        document.getElementById("First").style.display = 'Inline';
                        document.getElementById("Second").style.display = 'Inline';
                        document.getElementById("Third").style.display = 'Inline';
                    }
                    else {
                        document.getElementById("First").style.display = 'Inline';
                        document.getElementById("Second").style.display = 'None';
                        document.getElementById("Third").style.display = 'None';
                    }
                }
            });
        });
    });
4

1 回答 1

0

我希望这有帮助:

$(function () {
    var ajaxRequest = $.ajax({
        url: 'CallCenter/CallCenterAmt',
        type: 'POST',
        contentType: 'application/json' // don't need semicolon within quotes
    });
    ajaxRequest.done(function(data){
        alert('done');
        var firstDisplay = document.getElementById("First").style.display;
        var secondDisplay = document.getElementById("Second").style.display;
        var thirdDisplay = document.getElementById("Third").style.visibility;
        if (data == 2) {
            firstDisplay = 'Inline';
            secondDisplay = "Inline";
            thirdDisplay = "Hidden";
        } else if (data == 3) {
            firstDisplay = 'Inline';
            secondDisplay = 'Inline';
            thirdDisplay = 'Inline';
        } else {
            firstDisplay = 'Inline';
            secondDisplay = 'None';
            thirdDisplay = 'None';
        }
    });
    ajaxRequest.fail(function(){
        alert('fail');
    });
});

window.onerror = function(errorMessage, url, line) {
    var errorText = 'message: ' + errorMessage + '\nurl: ' + url + '\nline: ' + line;
    alert(errorText);
}
于 2013-05-16T16:56:24.857 回答