我有問題,當我做一個Ajax調用它不會到達服務器。我已經看到多個關於這個問題的帖子,但這些帖子不適合我。 發生的奇怪之處在於,當我在firefox中使用調試器開始時,此代碼正在工作,它也會觸發斷點。但是,當我在沒有調試器的情況下啓動項目時,它無法在firfox或chrome上運行。發生了什麼問題?Asp.net MVC 5 Ajax調用不觸發方法
這是我的Ajax調用:
$(document).ready(function() {
var events = [];
$.ajax({
type: "GET",
url: "Agenda/GetEvents",
success: function (data) {
$.each(data, function (i, v) {
events.push({
title: v.Subject,
description: v.Description,
start: moment(v.StartDateTime),
end: v.EndDateTime != null ? moment(v.EndDateTime) : null,
color: v.ThemeColor,
allDay: v.IsFullDay
});
console.log("Pushing");
})
GenerateCalender(events);
},
error: function (error) {
alert('failed');
}
})
function GenerateCalender(events) {
$('#calender').fullCalendar('destroy');
$('#calender').fullCalendar({
aspectRatio: 1.5,
defaultDate: new Date(),
timeFormat: 'HH:mm',
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
},
eventLimit: true,
eventColor: '#378006',
events: events,
eventClick: function (calEvent, jsEvent, view) {
$('#myModal #eventTitle').text(calEvent.title);
var $description = $('<div/>');
$description.append($('<p/>').html('<b>Starttijd: </b>' + calEvent.start.format("DD-MMM-YYYY HH:mm ")));
if (calEvent.end != null) {
$description.append($('<p/>').html('<b>Eindtijd: </b>' + calEvent.end.format("DD-MMM-YYYY HH:mm ")));
}
$description.append($('<p/>').html('<b>Beschrijving: </b>' + calEvent.description));
$('#myModal #pDetails').empty().html($description);
$('#myModal').modal();
}
})
}
})
,這是它需要去在AgendaController方法:
[HttpGet]
public JsonResult GetEvents()
{
var listofEvents = db.Events.ToList();
return new JsonResult{ Data = listofEvents, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
}
預先感謝您
首先它應該是'url:「/ Agenda/GetEvents」,(但總是使用'Url.Action()'來正確生成你的網址,並且你在瀏覽器控制檯中得到了什麼錯誤 –
@StephenMuecke I改變它爲Url.Action(),並沒有解決它在鉻上我沒有錯誤在Firefox上我得到這個錯誤:XML分析錯誤:找不到元素位置:http:// localhost:60628/Agenda/GetEvents linenumber1,column1:我也可以看到,當我嘗試控制檯登錄時,數據是undefiend – Diceble
@StephenMuecke當我搜索錯誤對象時,幾乎所有東西都是未定義的......最奇怪的是,我得到一個StatusCode 200一個響應是undefiend – Diceble