【问题标题】:grails IE ajax problemgrails IE ajax问题
【发布时间】:2011-10-12 20:53:08
【问题描述】:

我正在使用 grails 开发我的应用程序和“原型”库来执行 AJAX 调用 我在 IE 上遇到问题。在所有其他浏览器中,我的应用程序运行良好。 这是我的代码:

<html>
<g:form action="ajaxcall" id="recform">
    <g:select id="aseselect" name="art" from="${dropdownList}" optionKey="id" optionValue="value" noSelection="['':'- Select -']"/>

    <g:submitToRemote action="ajaxcall" value="submit" update="updatediv" />
</g:form>

<div id="updatediv"></div>

</div>
</html>

这是我的控制器代码:

def ajaxcall = {

    String toRender="";

    //code that makes db call and adds html into the toRender string

    render toRender;    
}

'toRender' 字符串包含无序列表的 html,它在 Firefox、chrome 和 safari 中呈现良好,但在 IE 中不呈现,它有时似乎无法获取整个列表或有时会得到一个空列表。根据 IE 的情绪,这种行为是完全不可预测的。

以前有人遇到过这个问题吗?我该如何解决这个问题?

谢谢

【问题讨论】:

标签: ajax internet-explorer grails prototypejs


【解决方案1】:

我修复了 IE (11) 浏览器 AJAX 使用 FormData() 发布到 Grails 控制器的问题,方法是删除

< meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

或者改成

< meta http-equiv="X-UA-Compatible" content="IE=Edge" />

在 HTML

部分中。

【讨论】:

    【解决方案2】:

    这是由于 IE 的缓存。我加了

    response.setHeader("Cache-Control", "no-store")
    

    到 ajax 调用的控制器方法,它告诉浏览器不要缓存该响应。

    所以你的控制器方法应该是这样的:

    def ajaxcall = {
    
        response.setHeader("Cache-Control", "no-store")
    
        String toRender="";
    
        //code that makes db call and adds html into the toRender string
    
        render toRender;    
    }
    

    这里有更详细的解释:

    Grails: best way to send cache headers with every ajax call

    【讨论】:

    • 非常感谢您的回答。我看到了你提到的那篇文章。然而,我没有成功。我应该在哪里添加上面的代码?在控制器内的“ajaxcall”中?我是 grails 新手,所以我还在学习。
    • 抱歉 - 我更新了我的回复。是的,它应该进入控制器方法;您很可能还需要手动清除 IE 的缓存/浏览历史记录。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    • 2012-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多