开发者

jQuery .load not working in ASP.Net MVC

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') {
            $('homeCont开发者_如何学运维ent').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.


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.


Try replacing the = with ==

if (id = 'menuMission') 

with

if (id == 'menuMission') 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜