Skip to content Skip to sidebar Skip to footer

Grails: Page Won't Redirect After Completed Ajax Call

This is my ajax call:

Solution 1:

Browsers won't redirect if an AJAX call returns a redirect. If you want to send the user to a new page after an AJAX call, you'll need to do so yourself in Javascript. Example:

def url = createLink(controller: 'user', action: 'authenticate')
render(contentType: 'text/html', text: "<script>window.location.href='$url'</script>")

Ensure the AJAX response gets rendered by the browser. With the grails remoteFunction tag you should specify an element to update with the update attribute.


Solution 2:

Redirecting the ajax call only redirects that call, not the whole page. To get the whole page to redirect, you either need to capture the redirected ajax call in the JavaScript and do a redirect from the JavaScript, or you need to have the page-level action do the redirect.


Post a Comment for "Grails: Page Won't Redirect After Completed Ajax Call"