gerrie-govaerts
asked on
Mvc Ajax Call returning Json result
Hello everybody
Why is this code, that returns a Json Result from the controller, incorrect? It does not give me the second alert (call completed). The first alert works well when changing a value in the listbox on my view.
Code in the controller: (I also tried using returning a JsonResult instead of ActionResult)
Thx!
Gerrie
Why is this code, that returns a Json Result from the controller, incorrect? It does not give me the second alert (call completed). The first alert works well when changing a value in the listbox on my view.
<script type="text/javascript">
$(document).ready(function () {
$("#MaterialsList").change(function () {
alert('changed');
$.getJSON("/Stock/LoadBrands", null, function (data) {
alert('call completed');
});
});
});
</script>
Code in the controller: (I also tried using returning a JsonResult instead of ActionResult)
public ActionResult LoadBrands()
{
var data = new { name = "Gerrie" };
return Json(data);[/b]
}
Thx!
Gerrie
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks a lot for the points!
If you handle the error function (with jQuery.ajax(), you should see clearly what happen, in your case a message worrying about the method)
error : function(data) { alert(data); },
Check the Controller action here :
http://weblogs.asp.net/mikebosch/archive/2008/02/15/asp-net-mvc-submitting-ajax-form-with-jquery.aspx
If you handle the error function (with jQuery.ajax(), you should see clearly what happen, in your case a message worrying about the method)
error : function(data) { alert(data); },
Check the Controller action here :
http://weblogs.asp.net/mikebosch/archive/2008/02/15/asp-net-mvc-submitting-ajax-form-with-jquery.aspx
ASKER