【问题标题】:IE Not Updating Asp.Net MVC3 Partial ViewIE 不更新 Asp.Net MVC3 部分视图
【发布时间】:2014-04-09 23:30:17
【问题描述】:

我有一个页面,其中包含通过 ajax 请求返回的部分视图的 div。

    $.ajax({
        url: 'CompleteSessions',
        success: function (data) {

            var selector = $('#complete-session-section');
            if (data.length > 0) {
                selector.html(data);
            }
            else {
                selector.append($(document.createElement('option')).html('No assessments'));
            }
        }
    });

局部视图本身有一个模型,并根据返回的会话数构造一个组合框。

    @using SmartQWeb.Models.Entities
@using SmartQWeb.Runtime;
@model IEnumerable<Session>


<span class="dropdown">
<select style="width: 75%" id = "complete-session-selector">
    <option id="-1">Select a Session</option>
    @foreach (Session session in Model.OrderByDescending(date=>date.StartTime))
    {
        if (session.Assessment != null)
        {
            <option id="@session.AssessmentId" value="@session.Id" title="Administered by: @session.User.Name" data-assessmentId="@session.AssessmentId">@session.Participant.AliasLookup.AliasId - @session.StartTime  </option>
        }
    }
</select>


</span>

问题在于,仅对于 IE,第一次加载页面时下拉菜单没有正确更新。我必须按 F5(有时控制 F5)才能刷新并查看组合框中的新条目。这对 Chrome 或 Firefox 来说不是问题。

【问题讨论】:

    标签: javascript jquery ajax asp.net-mvc internet-explorer-11


    【解决方案1】:

    jQuery ajax 请求的默认 'type' 参数是 'GET',IE 会缓存它。您可以在 ajax 请求中禁用缓存或切换到“POST”以防止这种情况发生--

    $.ajax({
        ...
        cache: false
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多