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

  • SEARCH
  • Home
  • 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 8836609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:32:07+00:00 2026-06-14T09:32:07+00:00

I have a gsp page that includes a JS function ( named sample) which

  • 0

I have a gsp page that includes a JS function ( named “sample”) which does an ajax call.

function sample() {
         var params = { office: {id: "testId"}, population: {id: "testId2"}};

        $.ajax({
            url: "http://localhost:8080/officeProj/mustache/list",
            cache: false,
            contentType: "application/json; charset=utf-8",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(params),
            complete:function(json){
                console.log(" reponse :"+ json);
            },
            success: function(officeData) {
                var template = "<h1>{{data.firstName}} {{data.lastName}}</h1>";
                var html = Mustache.to_html(template, data);
                $('#sampleArea').html(html);
            } ,
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("error :"+XMLHttpRequest.responseText);
            }
        })

    }

Now, this ajax call reaches the appropriate GRAILS controller and appropriate action,defined as:

def list = {

    withFormat {
        html { return [title: "Mustache" , data:[firstName:"Indiana", lastName:"Jones"], address:"NYC" ] }
        json {
            // extract the data to be rendered to the page
            println("processing JSON.....")
            render ([title: "Mustache" , data:[firstName:"Indiana", lastName:"Jones"], address:"NYC" ] as JSON)
        }
    }
}

The problem is that the control NEVER goes through the withFormat->json in the controller-action and hence I am not seeing the expected result.( When the control comes back to the gsp page, it goes through the the “complete” but not through the “success”. No error recorded. Can any one see any problem with my ajax call? Please let me know if I need to provide more information.Thanks in advance.

  • 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. Editorial Team
    Editorial Team
    2026-06-14T09:32:08+00:00Added an answer on June 14, 2026 at 9:32 am

    This is usually something that gets people, especially when moving from Grails 1.x to Grails 2.x. You have to read the docco carefully.

    emphasis in bold is mine…

    Another important factor to note is that the withFormat method deals
    with the response format and not the request format. As of Grails 2.0,
    there is a separate withFormat method made available on the request
    that you can use to handle the request format which is dictated by the
    CONTENT_TYPE header of the request:

    request.withFormat {
        xml { .. }
        html { .. }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following gsp page: <g:def var=incidentMngmntId value=${incidentMngmntInstance?.id}/> <g:link controller=ticketMngmnt action=list params=[incidentMngmntId :
I have a page/gsp that displays 3 different classes. This means that I need
I want to create a simple gsp page which will have an input box
I have a gsp page and on that have a ' <g:select> ' element
I have a .gsp, that displays a number in the page. The problem is,
I have a gsp page with a form that I would like to put
My question is, I have a page say view.gsp and containing a form that
I have a very simple gsp page that has a button. I'm trying to
in .gsp file i have javaScript function <script type=text/javascript> function getCurrentItemNumber(){ return document.getElementById('item_itemNumber').innerHTML.substr(6); }
I have the following code in my gsp <select onChange=${remoteFunction(action:'superior', controller:'employee', params: '\'name=\' +

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.