Jquery IIS的MVC3 JSON调用问题
我在MVC3用户管理和本地(VS2010)上工作,看起来都很好,但在IIS(7.5)上,它不会显示对JSON post的任何响应 表1适用于发电机的用户:Jquery IIS的MVC3 JSON调用问题,jquery,ajax,json,asp.net-mvc-3,iis,Jquery,Ajax,Json,Asp.net Mvc 3,Iis,我在MVC3用户管理和本地(VS2010)上工作,看起来都很好,但在IIS(7.5)上,它不会显示对JSON post的任何响应 表1适用于发电机的用户: this.init = function (tableSelector) { // get user table userTable = $(tableSelector); // fill the user table with all $.post('/{controllerName}/GetAllUsers', {}, functi
this.init = function (tableSelector) {
// get user table
userTable = $(tableSelector);
// fill the user table with all
$.post('/{controllerName}/GetAllUsers', {}, function (users) {
// add users to table
for (var i in users) {
appendUser(users[i]);
}
//initialize table sorter and pager
userTable.tablesorter({ widthFixed: true, widgets: ['zebra'] }).tablesorterPager({ container: $("#pager"), positionFixed: false, removeRows: false });
// bind user action link event handlers for all rows
userTable.on('click', '.delete-user', deleteUser);
userTable.on("click", ".unlock-user", unlockUser);
userTable.on("click", ".manage-roles", manageRoles);
});
}
路由注册方法:
public static void RegisterMe()
{
var routes = RouteTable.Routes;
using (routes.GetWriteLock())
{
routes.MapRoute("SimpleUserManagementRoute",
"SimpleUserManagement/{action}",
new { controller = "UserManagement", action = "GetAllUsers" },
new string[] { "SimpleMvcUserManagement" });
}
}
控制器部分:
public IUserAccountService _accountService { get; set; }
public JsonResult GetAllUsers()
{
var users = _accountService.GetAllUsers();
var result = from MembershipUser user in users
select CreateJsonUserObject(user);
return Json(result);
}
现在通过查看StackOverflow,我发现问题在于强编码URL。
参考:
我试着用参考资料中提到的url替换我的url,但当然没有用,因为我不知道在哪里/如何字符串化我的url:(,也不确定该解决方案是否适用于此
请帮助.TY!您的IIS是否配置了虚拟目录?如果将/{controllerName}/GetAllUsers放入浏览器会发生什么情况?您是否收到响应或404?您传递给$的URL。post
错误
应该是,
$.post(“/Register/GetAllUsers”,…)
//假设控制器是RegisterController
或
错误是什么?找不到400?内部错误500?通常您只需直接发布到路由,不需要包含控制器。您可以使用Douglas Crockfords JSON.js进行字符串化:我得到404。但是当我使用/{controllerName}/GetAllUsers
它确实像/UserManagement/GetAllUsers
一样显示它,只是它没有显示任何返回数据…响应时只有404如果您可以点击断点,您可以单步通过并看到var users是空的?我在服务器上没有开发环境,只有在本地,并且在本地一切都可以工作…这意味着,没有什么可调试的我的Url很好,因为它们在本地工作,我试过使用Url帮助程序,但同样的情况发生在服务器错误404上。
$.post('@Url.Action("GetAllUsers", "Register")',..