JSON function(Index) does not fire. Any Ideas?
<script type="text/javascript">
$(document).ready(function() {
alert("This alert is displayed :(");
$("form[action$='GetQuote']").submit(function() {
$.getJSON($(this).attr("action"), $(this).serialize(), function(Result) {
alert("This alert is not shown :(");
$("#name").html(Result.name);
$("#address").html(Result.address);
});
return false;
});
});
</script>
CONTROLLERS…
public JsonResult GetQuote(string dataName)
{
if (dataName != "" || dataName != null)
return new JsonResult { Data = new Result { name = "Hello", address = "World" } };
else
return null;
}
ASP.NET MVC 2.0 will throw an error if trying to do this with a HTTP GET by default. You can either make it a POST or add the instruction as suggested in this article:
http://mhinze.com/json-hijacking-in-asp-net-mvc-2/
which is:
return Json(data, JsonRequestBehavior.AllowGet);