0

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

Rob W
  • 341,306
  • 83
  • 791
  • 678
Sfairas
  • 932
  • 4
  • 13
  • 21

2 Answers2

0

I fixed the IE (11) browser AJAX using FormData() post to Grails controller problem by removing

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

or change it to

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

in the HTML <head> section.

webseaman
  • 1
  • 1
0

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

Community
  • 1
  • 1
R. Valbuena
  • 474
  • 3
  • 6
  • Thanks a lot for the answer. I came across the article you mention. However, I wasn't successful. Where exactly should I add the above code? In my 'ajaxcall' within the controller? I'm new to grails so I'm still learning. – Sfairas Jul 26 '11 at 08:03
  • Sorry about that - I updated my reply. Yes it should go in the controller method; you will most likely need to manually clear IE's cache/browsing history as well. – R. Valbuena Jul 27 '11 at 17:37