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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:15:53+00:00 2026-06-16T21:15:53+00:00

I need to make an Ajax query to call a method in a Service

  • 0

I need to make an Ajax query to call a method in a Service object that takes 3 parameters and returns a boolean. I then use this Boolean for a validation message that happens pre-post.

This is what I have at the moment (not working) but I’ve tried other things but to no avail. We’re using JQuery and Grails:

var isUnique = ${remoteFunction(
    service: 'Project', 
    action:'checkUniqueUserProjectId',
    params:{
        // These values are from  hidden fields in the form.
        // userId and projectId are string values and the group is an object
        uniqueId: userId,
        group: userGroup,
        projectId: myProjectId
    }
)}

Here’s the method that is called in the ProjectService:

// Check whether or not a Project with the provided uniqueId already exists 
// in the database that is not itself.
def checkUniqueUserProjectId(uniqueId,group,projectId) {
    def filterCriteria = Project.createCriteria()
    def projectList = filterCriteria.list {
        and {
            eq("userProjectId", uniqueId)
            eq("group", group)
            ne("id",projectId)
        }
    }

    if(projectList.empty)
        return true
    else
        return false
}

Any help would be greatly appreciated!

  • 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-16T21:15:54+00:00Added an answer on June 16, 2026 at 9:15 pm

    I ended up using a remote function with the code as follows:

    ${remoteFunction(action: 'isUniqueId', params: '\'uniqueid=\'+userId+\'&project_id=\'+myProjectId', onFailure:'$("#project").submit()', onSuccess:'verifyUniqueness(data, textStatus,detailsMessage)') }
    

    ….

    function verifyUniqueness(data, textStatus,detailsMessage) {
        if (data == 'false') {
            detailsMessage = detailsMessage + "A Project with the provided Project ID already exists.";
        }
    
        if (detailsMessage.trim() != '' ) { 
            stackedSummary.section('details', '<font style="color:red; font-weight:normal; line-height:0px;">' + detailsMessage + '</font>');
        } else {
            $('#project').submit();
        }
    }
    

    ProjectController

    def isUniqueId = {
        def project = Project.get(params.project_id)
        if (project == null) {
            render(projectService.checkUniqueUserProjectId(params.uniqueid, null, null)) as JSON
        } else {
            render(projectService.checkUniqueUserProjectId(params.uniqueid, project.group, project.id)) as JSON
        }
    }
    

    Thank you everyone for your help! You helped lead me in the right direction 🙂

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

Sidebar

Related Questions

I want to make an ajax call to server. I need to fetch the
I have two Ajax calls. I need to make sure that a JS function
Need a way to make element show in the div,but when i use ajax
I need to make a series (1-20) ajax calls and I need to have
I need to make this data variable global: $.ajax({ url: get_data.php, cache: false, dataType:
I need make all of my posts update. I use bulk upload for store,
I need the AJAX to listen to if a button is click. Then if
I've read about the jQuery.ajax method and believe this should be what I need
i need a tips, how to make a AJAX request with mootools, when some
I need make some action (dump statistical data) before the Dart program ends. The

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.