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);   }) }); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -