jquery - AJAX Request POST data to rails controller gives 404 -


i want post data rails controller via ajax request

my route: get "pki_login/authenticate" => "pki_logins#authenticate"

the js:

$.ajax({     type: 'post',     url: '/pki_login/authenticate',     datatype: 'json',     contenttype: "application/json; charset=utf-8",     success: function(data) {         alert("successful");       },     data: passcode }); 

then inside pki_logins_controller.rb have:

def authenticate   puts params[:passcode] end 

the authenticate.html.erb file contains h3 tag.

i can visit /pki_login/authenticate , works, when accessing via ajax 404 don't know if post works either

you're defining get route making post request.

try:

$.ajax({     type: 'get',     url: '/pki_login/authenticate',     datatype: 'json',     contenttype: "application/json; charset=utf-8",     success: function(data) {         alert("successful");       },     data: passcode }); 

or change route post , use post ajax request as:

# config/routes.rb post "pki_login/authenticate" => "pki_logins#authenticate" 

then ajax call:

$.ajax({     type: 'post',     url: '/pki_login/authenticate',     datatype: 'json',     contenttype: "application/json; charset=utf-8",     success: function(data) {         alert("successful");       },     data: passcode }); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -