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 8189125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:10:03+00:00 2026-06-07T03:10:03+00:00

I am new to ajax so maybe this is obvious. I’ve tried many different

  • 0

I am new to ajax so maybe this is obvious. I’ve tried many different not-working approaches. I have javascript that when you click on a button:

  1. an ajax call that grabs some data from a controller – returns an object
  2. display that data in a template that I will show on the page

Here is the javascript/ajax:

<script type="text/javascript">
  $("#show").click(function () {
    $.ajax({  url: '/Myproject/result/index',
              type: "POST",
              data: { id: id},

          success: function(result) {
             alert("Success:" + result);  // Can see getting object back.
          }});
    $(".resulttable").show();
  });

Here is the key line in grails view template:

<g:each in="${allResults}" status="i" var="result">
  1. How do I get the data from the javascript to the gsp code (ie allResults)?
  2. Do I have to “refresh” this template to display new data?

thanks.

  • 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-07T03:10:05+00:00Added an answer on June 7, 2026 at 3:10 am

    You just can’t make your javascript/jquery code populate things in the gsp, since the gsp is processed server-side and javascript is processed client-side, after the gsp rendered all html documents and populated them with your model. You need to be aware that your page was already processed, so things like ${variables} won’t be reloaded anymore. So when you do this:

    $(".resulttable").show();

    It’s not gonna show the result you’re waiting for. You have to use javascript code to reload your result table.

    So if you’re using ajax here, you should use the function success to alter your html table via javascript/jquery since you already have the response you wanted. Maybe this read can help you. Oh, and I think it would be better if in your ajax call, you would define a dataType (json works great in your case), like this:

    $("#show").click(function () {
        $.ajax({  url: '/Myproject/result/index',
                  type: "POST",
                  data: { id: id},
                  dataType: 'json',
                  success: function(result) {
                      alert("Success:" + result);  // Can see getting object back.
                  }});
        $(".resulttable").show();
      });
    

    Just to make clear what kind of response you’re getting from the controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is currently this Prototype code that does a PUT: new Ajax.Request(someUrl, { method:
I was working on a simple link that would initiate an ajax call. This
So I think I maybe missing something with Ext.Ajax.request(); So I have code that
Consider this code: new Ajax.Request('?service=example', { parameters : {tags : 'exceptions'}, onSuccess : this.dataReceived.bind(this)
I'm new to AJAX and PHP but I know that PHP is a server-side
Hey there, new to AJAX, JS.. Im trying to add to a Javascript/Ajax search
I'm completely new to the javascript and ajax world but trying to learn. Right
I'm very new when it comes to programming so maybe this is a walk
Disclaimer: I'm fairly new to AJAX! I've looked around, and I'm not sure which
I am new to MVC3 and Jquery. Maybe i am not taking the right

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.