我正在尝试使用 getJSON() 调用使 ajax 工作。当我导航到 /Home/GetWeather 时,我会在浏览器中返回 Json 数据。但是 jQuery 调用不起作用。有任何想法吗?当我在警报(“Hello”)上设置断点时,它从未命中。在萤火虫中,我没有看到任何 ajax 调用。有任何想法吗?
$(document).ready(function() {
$("#Button1").click(function() {
$.getJSON("/Home/GetWeather", null, function(data) {
alert("Hello");
});
});
});
控制器代码
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult GetWeather()
{
List<Weather> weather = new List<Weather>();
// populate weather with data
return Json(weather, JsonRequestBehavior.AllowGet);
}
}
看法:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function () {
$.getJSON("/Home/GetWeather", null, function (data) { //I hit breakpoint here, but in firebug I dont see any call, nothing
alert("Hello"); // Breakpoint here doesnt hit :(
});
});
});
</script>
</head>
<body>
<input id="Button1" type="button" name="Button1" value="Get Weather" />
<div id="Weather"></div>
</body>
</html>
我找到的解决方案被删除的任何原因???