2016-10-07 4 views
2

Ich erhalte eine Anfrage an http://localhost:3000/cars/1, aber der Server antwortet nicht JSON-Daten. Er sagt, wie dieKann keine JSON-Daten von Rails API

Started GET "/api/cars/1" for 127.0.0.1 at 2016-10-07 12:47:34 +0600 
Processing by Api::V1::CarsController#show as HTML 
Parameters: {"id"=>"1"} 
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."uid"  = $1 LIMIT $2 [["uid", "[email protected]"], ["LIMIT", 1]] 
Car Load (0.6ms) SELECT "cars".* FROM "cars" WHERE "cars"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]] 
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]] 
Started GET "/" for 127.0.0.1 at 2016-10-07 12:47:34 +0600 
Processing by Rails::WelcomeController#index as HTML 
Parameters: {"internal"=>true} 
(2.9ms) BEGIN 
Rendering /home/sahidul/.rvm/gems/ruby-2.2.3/gems/railties- 5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb 
Rendered /home/sahidul/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/templates/rails/welcome/index.html.erb (3.9ms) 
Completed 200 OK in 11ms (Views: 10.2ms | ActiveRecord: 0.0ms) 


(6.8ms) COMMIT 
Completed 200 OK in 25ms (Views: 1.3ms | ActiveRecord: 11.8ms) 

Meine Controller-Methode, wie die

def show 
    car= Car.find(params[:id]) 
    render json: car 
end 

Front-end Anfrage

ist

function getCar(id) { 
     return $http.get($auth.domain + '/api/cars/' + id); 
    } 

I devise_token_auth Juwel in Back-End und ng-token-auth verwenden im Frontend

+0

Versuchen Sie, '$ http.get ($ auth.domain + '/ api/cars /' + id);' zu '$ http.jsonp ($ auth.domain + '/ api/cars /' + id) zu ändern. ; ' – Pavan

+0

@ Md.Sahidul Islam .. im Grunde Ihre Anfrage an Server ist http Anfrage .. Es sollte JSON Anfrage sein. – Ann10

Antwort

4

Die Adresse .json an die URL

012 anhängen
$http.get($auth.domain + '/api/cars/' + id + '.json'); 

Hoffe, dass hilft!