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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:45:45+00:00 2026-05-27T22:45:45+00:00

In the below ‘simple’ Ajax login example, I’m using JQuery to submit form params

  • 0

In the below ‘simple’ Ajax login example, I’m using JQuery to submit form params to a Grail’s controller. However, the actual URL does not match the controller URL configured in the ajax call.

Html:

<div id="loginForm">
        <div id="ajaxLoginError">
        </div>
        <form name="ajaxLoginForm" action="ajaxLogin" id="ajaxLoginForm">
            <span class="pic"></span>
            <span class="close"></span>
            <input type="text" name="username" class="text focus" default="Username"
                value="${user?.username}" />
            <input type="password" name="password" class="text focus"
                default="Password" value="${user?.password}" />
            <button type="submit" name="login" id="ajaxLoginBtn">
                <span class="button"><span>Login</span> </span>
            </button>
            <label> <input type="checkbox" class="check" name="remember" />Remember
                me</label>
            <a href="#">Forgot username or password?</a>
        </form>
    </div>

Javascript:

$('#ajaxLoginBtn').click(function() {
    $('#ajaxLoginError').fadeOut();
    $.ajax({
        url: "${createLink(controller: 'user', action: 'ajaxLogin')}",
        type: 'GET',
        data: queryString,
        dataType: 'json',
        success: function(data) {
            if (data.isAuthenticated) {
                // Display user bar
                $('#loginUserBar').slideDown();
            }else {
                $('#ajaxLoginError').html(data.errorMsg).fadeOut();
            }
        }
    });
});

Also, can anyone verify my controller logic. I gather this is the correct way to parse a JSON response?

Server:

def ajaxLogin = {
    boolean isExists = false
    String errorMsg = ""
    def foundUser = User.findByEmailAndPassword(params.username, params.password) 
    if (foundUser) {
        isExists = true
    }else {
        errorMsg = "Login unsuccessful! Either the username, or password entered is incorrect."
    }
    render(content: 'text/json',
        loginResponse(isAuthenticated: isExists, errorMsg: errorMsg));
}

Similarly, is there anything I need to do to explicitly force Grails to use JQuery as the main javascript plugin?

  • 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-05-27T22:45:45+00:00Added an answer on May 27, 2026 at 10:45 pm

    There are a lot of different questions… 🙂

    1) is there anything I need to do to explicitly force Grails to use JQuery as the main javascript plugin?

    Install the jquery plugin if it’s not installed yet. You can also put a

    <g:setProvider library="jquery"/>
    

    at the beginning of your GSP (or in your layout) to explicitely set JQuery as the provider

    2) this is the correct way to parse a JSON response?

        log.info("Receive send request");
        def contentType = request.getHeader('Content-Type')
        log.trace("receive with ContentType: " + contentType)
        if (contentType && contentType.contains('application/json')) {            
            def results = request.JSON
            log.info("results received : ${results}")
        }
    

    You can add a if (request.xhr){} to test for ajax calls

    3) can anyone verify my controller logic.

    Nothing to say about the logic itself, you check for an existing login/password

    4) the actual URL does not match the controller URL configured in the ajax call.

    It’s difficult to answer with only what you told us. jQuery’s ajax call seems good, but we don’t know anything about the content of your queryString. I usually use $("#myForm").serialize() to send form to controllers
    I don’t understand your problem about URLs though…

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

Sidebar

Related Questions

Below is the jquery code I am using for my AJAX tabs Is there
Below I have a very simple example of what I'm trying to do. I
Below is a very simple example, randomly, if I click the step2 button the
Below is my $.ajax call, how do I put a selects (multiple) selected values
Below is the code of a simple html with a table layout. In FF
Below are two simple Cython methods I wrote. In g_cython() method I used additional
Below is the code which creates 9 buttons in gridlayout form on a specific
below is my simple code to start 5 threads, each one calls a wcf
Below is the code I'm using to run the query, parse the result set,
Below, I have written simple code that re-creates problems that have emerged as my

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.