Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么ajax调用没有被命中_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 为什么ajax调用没有被命中

Javascript 为什么ajax调用没有被命中,javascript,jquery,ajax,Javascript,Jquery,Ajax,此函数用于在页面加载时命中,现在显示第一个警报,但ajax调用中的警报没有显示。这似乎根本没有影响ajax调用。它应该在我的控制器中调用一个方法,但似乎不再命中它 $(function () { $(document).ready(function () { alert("2"); $.ajax({ url: 'CallCenter/CallCenterAmt', t

此函数用于在页面加载时命中,现在显示第一个警报,但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';
                    }
                }
            });
        });
    });
我希望这有助于:

$(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);
}

可能是ajax调用未成功。你能看到使用某种web开发工具(在许多浏览器中是F12)添加
error:function(){console.log(argements)}
发生了什么吗就像你有一个成功处理程序一样,你需要一个错误处理程序来覆盖你的所有基础。你不需要同时添加
$(function(){})
$(document).ready(函数(){})嵌套-它们做相同的事情,因此它们是冗余的。(这不会解决任何问题,我只是指出它)也删除
在此
contentType:'application/json;'之后