I am fairly new to working with ajax, and I find myself in need of using it for my Rails application. Here is the function in my controller:
def check_code
input = params[:input]
code = params[:code]
if input == code
return true
else
return false
end
end
Here is the JavaScript I have tried so far:
$('#submit_me').click(function() {
var input_code = $('.input_code').val();
var isValid = $.ajax({
url: '/check_code/'+input_code+'/<%= @code %>',
type: 'get',
contentType: 'application/json; charset=UTF-8',
});
alert(isValid)
});
I am struggling to make this ajax call work. My goal is to invoke the controller function and capture the returned value in JavaScript. Any assistance on this would be greatly appreciated. Thank you.