为什么ajax呼叫没有被击中

时间:2013-05-16 16:14:09

标签: javascript jquery ajax

这个函数用于点击页面加载现在第一个警报显示但是ajax调用内部没有显示。这个doenst似乎完全击中了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';
                    }
                }
            });
        });
    });

1 个答案:

答案 0 :(得分: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);
}