我正在尝试执行一个简单的 Ajax 调用来从 HTML 页面注册用户,MVC 4 中的函数被调用并且运行良好,但它返回的内容永远不会触发 Ajax 调用中的“成功”函数。
如果我使用浏览器手动访问 Register() 函数,它运行良好并返回我想要的消息,但不是通过 Ajax
function register() {
var userModel = {
phoneNumber: "1236663",
displayname: "yasuuu",
}
$.ajax({
type: "POST",
url: "http://localhost:13234/home/register",
data: userModel,
success: function (response) {
$('#deleteThisDivButNotItsContent').html(response)
}
})
}
public ActionResult Register(string PhoneNumber, string DisplayName)
{
// Some working code here ...
ViewBag.Message = "Some Message"; // just trying to display simple text
return View();
/* tried all of the lines below too */
//return this.Json("1234");
//return Json("{ result : true }");
//return PartialView("ShowResultPartial", JsonRequestBehavior.AllowGet);
//CommentSection commentSection = new CommentSection();
//return PartialView("CommentSection");
//return PartialView("CommentSection", commentSection);
//return Json(new { success = true, response = "Saved ok" });
}
我正在使用 JQuery 2.0.3