Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 172335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:08:52+00:00 2026-05-11T13:08:52+00:00

I am developing a grails application which uses lot of ajax.If the request is

  • 0

I am developing a grails application which uses lot of ajax.If the request is ajax call then it should give response(this part is working), however if I type in the URL in the browser it should take me to the home/index page instead of the requested page.Below is the sample gsp code for ajax call.

<g:remoteFunction action='list' controller='todo' update='todo-ajax'>  <div id ='todo-ajax'> //ajax call rendered in this area </div> 

if we type http://localhost:8080/Dash/todo/list in the browser URL bar, the controller should redirect to http://localhost:8080/Dash/auth/index

How to validate this in controller.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:08:52+00:00Added an answer on May 11, 2026 at 1:08 pm

    It’s quite a common practice to add this dynamic method in your BootStrap.init closure:

        HttpServletRequest.metaClass.isXhr = {->          'XMLHttpRequest' == delegate.getHeader('X-Requested-With')     } 

    this allows you to test if the current request is an ajax call by doing:

    if(request.xhr) { ... } 

    The simplest solution is to add something like this to your todo action:

    if(!request.xhr) {      redirect(controller: 'auth', action: 'index')     return false } 

    You could also use filters/interceptors. I’ve built a solution where I annotated all actions that are ajax-only with a custom annotation, and then validated this in a filter.

    Full example of grails-app/conf/BootStrap.groovy:

    import javax.servlet.http.HttpServletRequest  class BootStrap {       def init = { servletContext ->          HttpServletRequest.metaClass.isXhr = {->             'XMLHttpRequest' == delegate.getHeader('X-Requested-With')         }       }      def destroy = {      } }  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a application in grails which uses lot of ajax.In one part
I am developing a web application in grails which uses lot of ajax.I need
I am developing grails application which uses file searching.For that I wrote the following
I am developing a Grails-application which uses several databases, others are read-only and 1
I am developing an application which should work under different languages (german, spanish, etc).
I'm developing a Grails application to a school work. Typically, this is the URL
I am developing a grails application which has codenarc plugin. And also I am
I'm developing a Grails (Version 1.3.3) Web-Application using the Grails Spring-Security Plugin, Spring-Security-Core-1.0.1 (which,
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I'm developing a Grails web application (mainly as a learning exercise). I have previously

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.