Search code examples
ajaxinternet-explorergrailsprototypejs

grails IE ajax problem


I'm using grails to develop my application and the 'prototype' library to do an AJAX call with which I'm having a problem with on IE. In all other browsers my application works fine. Here is my code:

<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>

And this is my controller code:

def ajaxcall = {

    String toRender="";

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

    render toRender;    
}

The 'toRender' string contains html of an unordered list which renders fine in firefox, chrome and safari but not IE which seems to not get the whole list sometimes or get an empty list some of the times. The behaviour is totally unpredictable depending on IEs mood.

Has anyone come across this issue before? How can I solve this?

Thanks


Solution

  • It's due to IE's caching. I add

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

    to controller methods for ajax calls, which tells the browser not to cache that response.

    So your controller method should look something like:

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

    There's a more detailed explanation here:

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