检查用户名可用性 [英] Check username availability
问题描述
我有一个表格,以用户登录:
I have a form to user login:
<%= form_tag(@action, :method => "post", :name => 'signup' ,:onSubmit => 'return validate();') do %>
<%= label_tag(:user, "Username:") %>
<%= text_field_tag(:user) %>
我要检查是否有后,立即在数据库中的用户名:用户现场失去焦点。我可以忽略此事件与JavaScript的形式,但我不能从发送javascipt的code Ruby的AJAX请求。
I want to check if there is the username in the database immediately after :user-field lost focus. I can override this event on the form with javascript, but I can not send Ruby-AJAX request from javascipt code.
有没有什么办法来检查用户名,而不在窗体上添加其他控件(按钮,链接)?
Is there any way to check username without adding additional controls (buttons, links) on the form?
推荐答案
为了什么原因,你能不能发送通过JavaScript code Ajax请求?
For what reason can you not send an ajax request from javascript code?
最好的办法是将发送GET Ajax请求时,焦点将丢失。 GET请求可以返回true或false而JavaScript然后可以反映这个页面上。
The best way would be to send a GET ajax request when the focus is lost. The get request could then return true or false and your javascript could then reflect this on the page.
这篇关于检查用户名可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!