0

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.

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it is the id. I started with the hash, tried again, then changed 'homeContent' to be a class and tried with the period. None of it works. The JavaScript executes without errors.
You might still be getting server errors, the script won't throw that. Try monitoring the web traffic using something like Fiddler2 to check that the data is being returned.
3

Try replacing the = with ==

if (id = 'menuMission') 

with

if (id == 'menuMission') 

1 Comment

Thanks, and for the record I did also have to put the # symbol back in like David suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.