我的项目将不带/主页上到底要不要工作基本URL,它返回一个Ajax错误。我怎样才能确保若无首页/指数是进入基地的URL,这将不返回错误的工作?
我可以看到,在服务器端GetTaskLog返回一个404未找到错误。 GetTaskLog是在我家的一个功能是用于从数据库中检索数据。当我添加/家庭对URL GetTaskLog工作正常。它检索数据并没有错误。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
阿贾克斯:
"ajax": {
"url": "../Home/GetTaskLog",
"type": 'POST',
"content-type": "application/json; charset=utf-8",
"processData": false,
"dataType": "json",
"headers": "headers",
"data": "window.JSON.stringify(obj)",
//"headers": { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() },
//"data": { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() },
"traditional": true,
"dataSrc": function (data) {
return JSON.parse(data);
},
},
在route.MapRoute默认说,如果应用程序对URL没有像{控制器} / {行动} / {ID}它将返回首页/索引。所以,你需要改变默认参数
我的问题的解决办法是改变AJAX网址:
"ajax": {
"url": "/WTM/Home/GetTaskLog"
}