I am trying to get the success function from an AJAX call to fire. I know it is properly working because I am hitting my own API and I can see it is properly hitting the URL and the server is outputting a HTTP 200.
I figured it was because the server is outputting json, so I tried to account for that in the AJAX call, but still the success function will not work. Here is my code
ajax
$.ajax('http://localhost:3000/api/users/show/:id', {
type: 'GET',
dataType: 'json',
contentType: "application/json",
data: {
id: 1
},
success: function(response) {
return alert("Hey");
}
});
api method
class UsersController < ApplicationController
respond_to :json
def show
respond_with User.find(params[:id])
end
end
server logs
Started GET "/api/users/show/:id?id=1" for 127.0.0.1 at 2013-08-02 20:36:42 -0700
Processing by MainController#index as JSON
Parameters: {"id"=>"1", "path"=>"api/users/show/:id", "main"=>{}}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Rendered main/index.html.erb within layouts/application (0.6ms)
Completed 200 OK in 146ms (Views: 144.3ms | ActiveRecord: 0.5ms)
[2013-08-02 20:36:42] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true