这真的很奇怪,我不知道我哪里出错了。
这是我的控制器:
namespace MvcAJAX.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Called()
{
var retObject = new { rollNo = 2, name = "Deepanjan" };
return Json(retObject);
}
}
}
这是我的索引视图:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script>
/// <reference path="~/Scripts/jquery-1.7.1.js" />
$(document).ready(function () {
$('#button1').click(function () {
$.getJSON("/Home/Called",function () {
alert('Working!');
$('#p1').text("Roll Number was " + data.rollNo + " and the Name was " + data.name);
});
});
});
</script>
<h1>This page demos Load with callback function!</h1>
<input type="button" id="button1" value="Click Me!"/><br />
<p style="height:200px" id="p1"></p>
<hr />
我的 getJSON 根本不起作用,我什至没有收到警报。怎么了?