I’m trying to render an ajaxButton in Lift that, once clicked, updates a SessionVar and then goes to another page using href:
def render ={
"li *" #> userItems.map(item =>
"li.button_open" #> SHtml.ajaxButton("Open", () => ajaxButtonOpen(item),
"class" -> "btn btn-primary", "href" -> {Site.menuItem.url})
)
}
def ajaxButtonOpen(item:Item) : JsCmd = {
UsersCurrentItemId apply item._id
JsCmd.unitToJsCmd(Unit)
}
This code will execute ajaxButtonOpen but will not go to the Site.menuItem. I’ve tried other alternatives such as:
"li.button_test" #> <a class="btn btn-primary" href= {Site.menuItem.url} onClick="{ajaxButtonOpen(item)}"> "Open"</a>
Does anyone know where I’m going wrong? Any help would be greatly appreciated.
I would do something like this:
I replaced the
Noopreturn from your method with aRedirectTo. TheJsCmds.RedirectTowill issue a javascript redirect to the new page and should accomplish what you are looking for.Alternately, you could use your original
ajaxButtonOpenfunction withSHtml.onEventto add the ajax event handler to your link: