简体   繁体   English

jQuery .load在ASP.Net MVC中不起作用

[英]jQuery .load not working in ASP.Net MVC

I am trying to do a jQuery AJAX call on a ASP.Net MVC page. 我正在尝试在ASP.Net MVC页面上进行jQuery AJAX调用。 I can step through the call back function in my debugger and see that the javascript is executing, but the does not update. 我可以在调试器中逐步执行回调函数,并看到javascript正在执行,但不会更新。

<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. $('homeContent').load()的调用正在工作。 I can confirm I have data, but the div does not update. 我可以确认我有数据,但是div不会更新。

Assuming that homeContent is the id of the div you need to prefix it with a hash: 假设homeContent是div的ID,则需要在其homeContent加上一个哈希:

 $('#homeContent').load('Home/Mission');

If it's the class then prefix it with a period: 如果是该类,则在其前面加上句点:

$('.homeContent').load('Home/Mission');

JQuery uses CSS selectors. jQuery使用CSS选择器。

-- -

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). 如果您的AJAX调用失败,那么它将以静默方式进行(您可能会从服务器收到错误500,除非您在完整的.ajax JQuery方法上连接了错误委托,否则该错误将在AJAX调用中隐藏)。

Check that data is being returned from the server using something like Fiddler . 使用Fiddler之类的工具检查是否正在从服务器返回数据。

Try replacing the = with == 尝试用==替换=

if (id = 'menuMission') 

with

if (id == 'menuMission') 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM