Reputation: 1577
I am trying to do a jQuery AJAX call on a ASP.Net MVC page. I can step through the call back function in my debugger and see that the javascript is executing, but the does not update.
<asp:Content ID="Content2" ContentPlaceHolderID="MenuContent" runat="server">
<% Html.RenderPartial("homeMenu"); %>
<script type="text/javascript">
InitHomeMenu('homeMenu', function (menuItem) {
var id = menuItem.attr('id');
if (id = 'menuMission') {
$('homeContent').load('Home/Mission');
}
else if (id = 'menuSuggestions') {
$('homeContent').load('Home/Suggestions');
}
});
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<div id="homeContent">
<% string control = ViewData["Control"] != null ? ViewData["Control"].ToString() : "Mission";
Html.RenderPartial(control); %>
</div>
</asp:Content>
The call to $('homeContent').load()
is working. I can confirm I have data, but the div does not update.
Upvotes: 0
Views: 1950
Reputation: 15085
Try replacing the = with ==
if (id = 'menuMission')
with
if (id == 'menuMission')
Upvotes: 3
Reputation: 17018
Assuming that homeContent
is the id of the div you need to prefix it with a hash:
$('#homeContent').load('Home/Mission');
If it's the class then prefix it with a period:
$('.homeContent').load('Home/Mission');
JQuery uses CSS selectors.
--
If your AJAX call is failing then it will do so silently (you might be getting an error 500 from the server, this is hidden on AJAX calls unless you hook up an error delegate on the full .ajax
JQuery method).
Check that data is being returned from the server using something like Fiddler.
Upvotes: 5