Take the 2-minute tour ×

I have strange problem: I'm checking if email is already taken, which user is entering.

It is working in simple page, but when I'm trying to call it on modal - it doesn't work.

Here is jQuery:

 $('#user_email').focusout(function() {
  $.getJSON('', { email: $('#user_email').val() }, function(data) 
    { $('#submit').attr('disabled', 'disabled'); }//disable submit

my HTML:

        <input id="user_email" name="user[email]" size="30" type="email" value="">
        <input class="btn" id="submit" name="commit" type="submit" value="Create an account">

my action and route to it:

def checkemail
 respond_to do |format|
   format.jsonr do
    if User.where(email: params[:email]).exists? 
      render :json => {
            :status  => :ok,
            :message => "Success!"

checkemail        /checkemail

also added mimetype

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

but as I see in log it seems to be, that action isn't calling. However all the same things are working in other project.

Can someone tell me where can be the problem ?

share|improve this question
Try removing the part. You probably got cross-domain issue. –  jdoe Sep 12 '12 at 14:11
@jdoe,hello again) it is working in simple page $.getJSON('/checkemail.jsonr', but doesn't work on modal. –  MID Sep 12 '12 at 14:17
add comment

2 Answers

up vote 0 down vote accepted

Vote this answer down if you want, let me whip out the ajax ruby rails checklist. Since it works on simple page and not modal, it has to be a javascript issue.

1) Make sure your jquery is in the $(document).ready() block. 2) Test your jquery listeners on $('#user_email'). I'm not a fan of alerts() but use console.log("blah");

3) try a simple ajax request without jsonr response?

Thats all i gotta say.
Good luck!

share|improve this answer
thanks for the answer! I found problem - all because I have a lot of forms, that contains the same input id. I forgot about that) –  MID Sep 13 '12 at 6:01
It's always those that gets you :) –  Phu Phan Sep 13 '12 at 16:24
add comment

Not sure how your modal is being done, but are you sure that your modal has access to the relevant jQuery function, is it included? Test that the jQuery focusout function is being run by sticking an alert("test"); or something in the function.

share|improve this answer
@Campbell, it seems to be not working $('#user_email').focusout(function() { alert('super'); } - no alert –  MID Sep 12 '12 at 14:58
Where is your HTML form located, and does that file have an <%= javascript_include_tag "my_javascript_file" %>? –  Mike Campbell Sep 12 '12 at 15:00
it is located in devise/registrations/new. I'm running jQuery validation there, so yes it include javascript file. –  MID Sep 12 '12 at 15:04
tried different variants - none of them are working - $('#user_email').click(function() { alert("Handler for .click() called."); }); - this too –  MID Sep 12 '12 at 15:12
one way or another, that jquery event handler isn't hooked to your form element, hence my suspicions about your include. whatever you do when you move your form from your "simple page" to your "modal", you're taking it out of the scope of your jquery function -- i believe. –  Mike Campbell Sep 12 '12 at 15:15
show 2 more comments

Your Answer


