【发布时间】:2013-08-04 04:47:06
【问题描述】:
我正在尝试执行一个简单的 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
【问题讨论】:
-
我已经在互联网上搜索了几个小时,但找不到任何东西:(
-
您使用的是哪个版本的 jQuery?您应该使用带有
.done(...)的承诺/延迟样式,而不是使用success -
我认为成功已经过时了。尝试完成。 http://api.jquery.com/jQuery.ajax/
-
使用 .done(...) 它不起作用。但是当我像 Dmytro 所说的那样使用完整时,它确实进入了 .complete(function(data) 的主体,当我使用 JSON.stringify(data) 解析返回参数时,它变成 {"readyState":4,"status ":404,"statusText":"错误"}
-
您的浏览器控制台是否出现错误?
标签: c# asp.net-mvc jquery actionresult