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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:29:15+00:00 2026-06-07T14:29:15+00:00

I am trying to send data to my controller from an ajax function that

  • 0

I am trying to send data to my controller from an ajax function that needs to have multiple levels, so something like this:

{
  "lob": {
    "TESTING": [
      {
        "name": "color",
        "value": "1"
      },
      {
        "name": "time",
        "value": "2"
      },
      {
        "name": "jeremy",
        "value": "3"
      },
      {
        "name": "fourtytwo",
        "value": "4"
      },
      {
        "name": "owl",
        "value": "5"
      },
      {
        "name": "why",
        "value": "6"
      },
      {
        "name": "derp",
        "value": "7"
      },
      {
        "name": "where",
        "value": "8"
      }
    ]
  }
}

but when it sends to grails I am getting this when I print out the params

[lob[TESTING][4][value]:5,
 lob[TESTING][3][name]:fourtytwo,
 lob[TESTING][6][name]:derp,
 lob[TESTING][5][name]:why,
 lob[TESTING][3][value]:4,
 lob[TESTING][1][value]:2,
 lob[TESTING][2][value]:3,
 lob[TESTING][5][value]:6,
 lob[TESTING][1][name]:time,
 lob[TESTING][0][value]:1,
 lob[TESTING][6][value]:7,
 lob[TESTING][0][name]:color,
 lob[TESTING][7][value]:8,
 lob[TESTING][4][name]:owl,
 lob[TESTING][7][name]:where,
 lob[TESTING][2][name]:jeremy,
 action:save,
 controller:LOB]

The data I am sending from JavaScript:

{
    lob: {
        TESTING: $form.serializeArray()
    }
}

I have been reading multiple forums saying using JSON.parse or request.JSON but these solutions do not seem to be fixing my problems. I want to be able to access the data like

params.lob.testing.each{ a->
    println a
}  

I will be doing alot more than just that but it would be nice to be able to access the data in that fashion. I am using Grails 2.1 and Jquery 1.7.2

  • 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-07T14:29:16+00:00Added an answer on June 7, 2026 at 2:29 pm

    Actually Grails makes it very easy. I’ve taken your test data and ran it through the following:

    import grails.converters.JSON
    
    class LobController {
    
        def save = {
           def json = request.JSON
           json.lob.TESTING.each {item->
             println "Name: ${item.name} - Value: ${item.value}"
           }
          //render something back if you need to here
      }
    }
    

    And it outputs:

    Name color - Value: 1
    Name time - Value: 2
    Name jeremy - Value: 3
    Name fourtytwo - Value: 4
    Name owl - Value: 5
    Name why - Value: 6
    Name derp - Value: 7
    Name where - Value: 8
    

    I created a UrlMapping entry like this (you probably already have this):

    "/myApi"(controller: "lob", parseRequest: true) {
                action = [POST: "save"]
    }
    

    The parseRequest: true will automatically parse the incoming JSON.

    I found a `serializeJSON’ function that might replace the serializeArray() to format this for JSON. The following was provided by Arjen Oosterkamp on the jQuery serializeArray page:

    (function( $ ){
    $.fn.serializeJSON=function() {
    var json = {};
    jQuery.map($(this).serializeArray(), function(n, i){
    json[n['name']] = n['value'];
    });
    return json;
    };
    })( jQuery );
    

    Simply use as $(‘form’).serializeJSON();

    All credit for that function goes to Arjen Oosterkamp…

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

Sidebar

Related Questions

I'm trying to send data to the Controller from the View. I have a
I am trying to send data from an activity to service via intents. This
I'm trying to send some data via JQuery ajax to a grails controller Here's
I'm trying to call a controller method from a javascript function, I read that
Actually I am trying to send data from jQuery to Spring controller and in
I am trying to send data as a model from an html form to
I am trying to send data through intent from one activity to another. But
I am trying to send data from PHP Client to Python Server. CLIENT <?php
I am trying to send some JSON data to my ASP.NET MVC3 controller action
I am trying to send the POST data from java to a PHP page.

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.