I have a link on an HTML page that is intended to refresh a div via Ajax.
The HTTP GET succeeds. I hit a breakpoint in the controller (it’s an ASP.Net MVC 3 app), and I can see in the IE9 Network Profiler that the call happens when I click the link, returns an HTTP status 200, and the Response Body is exactly as I would expect.
However, my jQuery success method is not invoked.
Here’s the code:
<script type="text/javascript">
$(document).ready(function () {
$('#add').click(function (e) {
alert('I DO display');
$.get('/Home/MyController?id=1&add=True&sub=3'), function (data) {
alert('I do not display');
$('#analysis').html(data);
};
e.preventDefault();
});
});
</script>
What am I missing?
It looks like it’s just a syntax issue. Try this:
The function was not being sent as a parameter because you closed the get call’s parentheses too early. Javascript then doesn’t complain that you define an anonymous function for no reason.