How to check user email uniqueness and pass result to jQuery?

后端 未结 1 581
南笙
南笙 2021-01-28 18:13

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 su

相关标签:
1条回答
  • 2021-01-28 18:43

    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 讨论(0)
提交回复
热议问题