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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:09:41+00:00 2026-06-11T15:09:41+00:00

I have this problem : I’m checking user email in controller and sending json

  • 0

I have this problem : I’m checking user email in controller and sending json successfull response if it is already taken and add css styling of input, also I need to prevent submit and add some message.

Here is my checkemail action ( used this article – http://paydrotalks.com/posts/45-standard-json-response-for-rails-and-jquery ):

def checkemail
  if !User.where('email = ?', params[:email]).empty?
    format.jsonr do
      render :json => { 
        :status => :ok, 
        :message => "Success!",
      }.to_json
    end
  end
end

and in my routes:

         checkemail GET    /checkemail(.:format)

          match "/checkemail", to: 'edit_user#checkemail'

and my jQuery:

   $('#user_email').focusout(function() {
    $.getJSON('/checkemail', { email: $('#user_email').val() }, function(data) {
        $('#user_email').addClass("error");
      });
   });

my HTML input code:

     <input id="user_email" name="user[email]" size="30" type="email" value="">

from mime_type initializers file:

    Mime::Type.register_alias "application/json", :jsonr, %w( text/x-json )

From Fiddler:

  Request : GET /checkemail?user@mail.com HTTP/2.0

  Response(RAW tab) : 
  Missing template edit_user/checkemail

  JSON tab is empty

QUESTIONS: How to inspect is json request sent ? How can I prevent submission form and add some message ?

  • 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-11T15:09:43+00:00Added an answer on June 11, 2026 at 3:09 pm

    I would do it like this:

    $('#element').focusout(function() {
      $.getJSON('PATH_TO_EMAIL_CHECK_ACTION', { email: $('#element').val() }, function(data) {
        // The data should tell you if its unique or not, you do something
        // here depending on response 
      });
    });
    

    And in the controller, check if the email is taken. If its not, send back render json with status OK and message success. You can check if the status is success in your callback where the comment is above.

    jquery focusout – http://api.jquery.com/focusout/

    jquery getJSON – http://api.jquery.com/jQuery.getJSON/

    About json responses in controller – http://paydrotalks.com/posts/45-standard-json-response-for-rails-and-jquery

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

Sidebar

Related Questions

I have this problem: $id is id for each user $img = 'http://www.somesite.com/pictures/'; $no_img
I have this problem whereby, i have created a user defined function within php.
I have this problem where I have created a User Control which mimics a
i have this problem: as i can add list to one list? i have
i have this problem, im using live preview, while the user is typing they
I have this problem that I cannot fix. From my @Controller , i can
I have this problem, which I am dealing with for some time already. At
I have this problem with my view-controller relation. This is the controller: <?php class
I have this problem with Headers already sent with Magento. I get this error:
I have this problem: I want to generate a new source code file from

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.