Search code examples
timeoutliftajaxform

How to avoid ajax timeouts on lift?


I'm using ajax+comet to build an iterative form. When it is submited, an output file is downloaded.

def render = ajaxForm(bind("form",/*...*/
  "submit" -> ajaxSubmit("Calculate",result _)))++hidden(result _)

private def result : JsCmd = {
  /* Some really time-consuming calculations */
  JsCmds.RedirectTo("/result/"+uniqueId)
}

It works most cases. Although, as there are some really long-lasting calculations, I'm getting the "the server could not respond" message (sometimes it just doesn't redirect with no error message).

I tried to reconfigure the ajax timeout:

LiftRules.ajaxPostTimeout = Int.MaxValue

But even than It's still not redirecting.

I could also decouple the redirect part from the calculations and do something like:

{val func = ajaxInvoke({() => JsCmds.RedirectTo("/result/"+uniqueId)})._2.cmd
Script(OnLoad(func))}

But I need to replace OnLoad for something that works on reRender and not only on full page reload. Or maybe to force somehow my page to reload without client iteraction.


Solution

  • LiftRules var ajaxPostTimeout = 5000 //m