gpt4 book ai didi

c# - 使用 HTTPStatusCodeResult 和 jQuery 的自定义错误消息

转载 作者:太空狗 更新时间:2023-10-29 20:05:39 35 4
gpt4 key购买 nike

我有一个 Controller 操作,可以将一些 JSON 结果返回到 jQuery Full Calendar 插件。如果出现错误,我会返回带有自定义错误消息的 HTTPStatusCodeResult,但我无法显示自定义错误消息。警告框中显示的是默认的 Http 状态(即:“禁止”或“内部服务器错误”)

返回错误信息的 Controller 代码

else if(id != CurrentUser.UserId)
{
return new HttpStatusCodeResult(403, "You are not authorised to view this.");
}
else
{
return new HttpStatusCodeResult(500, "There was an error on the server.");
}

jQuery 代码

$(document).ready(function () {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
height: 600,
eventSources: [{
url: events,
type: 'Get',
error: function(response, status, error) {
alert(response.statusText);
}
}],
allDayDefault: false,
selectable: true,
eventClick: function (event) {
if (event.url) {
$('#details').load(event.url);
}
},

最佳答案

其实代码完全没有问题。问题出在 Visual Studio 中的 ASP.NET 开发 Web 服务器上。我切换到使用 IIS Express,它工作正常。

关于c# - 使用 HTTPStatusCodeResult 和 jQuery 的自定义错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10348111/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com