Reputation: 2584
I'm using ruby on rails + jquery ajax
My function is for user check availability for new user registration.
function checkavailablity(){
var username = jQuery("#user_email").val();
var allNodes = 'name=' + username;
var capture;
if ((username).length > 0) {
jQuery('#availability').show().text("Checking...");
jQuery.ajax({
url: "/user_available",
data: allNodes,
success: function(result) {
// Call this function on success
alert(result);
// showResponseRegisterCheck( result );
// return result;
},
error: function() {
alert('Error occured');
}
});
} else {
jQuery('#availability').addClass('show_msg');
jQuery('#availability').show().text('Please enter a valid email id');
return false;
}
}
===========================================================================
and on rails my method is
def user_available
render :nothing => true
p user_email = params[:name]
p @user_email = User.where("email = ?",user_email).first
if @user_email.nil?
@ww = "yes"
else
@ww = "no"
end
return @ww
end
=====================================================================
my problem is
In my ajax-sucess I got no output but
in my rails method I'm returning yes or no value.
Upvotes: 2
Views: 1062
Reputation: 371
How about changes like followings.
- render :nothing => true
- return @ww
+ render :text => @ww #at the last line
Upvotes: 3