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