javascript - Call ruby function through AJAX -
i barely know ajax, , need use rails application. function here (controller function):
def verify_code input = params[:input] code = params[:code] if input == code return true else return false end end
the javascript have attempted:
$('#submit_me').click(function() { var input_code = $('.input_code').val(); var bool = $.ajax({ url: '/verify_code/'+input_code+'/<%= @code %>', type: 'get', contenttype: 'application/json; charset=utf-8', }); alert(bool) });
i have idea how ajax going. trying call controller function , getting return value javascript. can please me this? thanks.
you there! need implement "done" callback (= javascript function executed on success of ajax request):
try this:
$('#submit_me').click(function(event) { event.preventdefault(); var input_code = $('.input_code').val(); $.getjson('verify_code/'+input_code+'/<%= @code %>').done(function(data){ alert(data); }) });
- jquery's getjson method: http://api.jquery.com/jquery.getjson/
Comments
Post a Comment