-1

i have the following url "http://localhost:3000/api/user/" and is work fine in the browser, but when i put it in my ionic service code return $resource('/api/user/'); is return

data : cannot Get /api/user\n

and when i change the url to url from some api in the web is work fine and get the data right .. please what the wrong here.

Ebrahim Ze
  • 29
  • 1
  • 11
  • This might sound silly but if you have copied it from some pdf it might be using some weird ascii characters happened to me once. Just re-type it by hand. – rtn Aug 19 '16 at 15:48
  • that's really silly, but i didn't copy it and i retype the code and the same problem – Ebrahim Ze Aug 19 '16 at 16:17
  • Would guess its more to do with your server than the client side code. Get rid of the trailing slash and add the headers for content type etc. – rtn Aug 19 '16 at 16:27

1 Answers1

0

Your problem is link to the port :3000. When you write /api/user/, angular go to search your url on http://localhost/api/user/ and not http://localhost:3000/api/user/.

So to resolved this issue you have to pass all your url to the $ressource() and not only the last part.

  • now it return > {data :null,status:-1,config:{methode:get,transformRequest:[null],transformResponse:[null],url:"http://localhost:3000/api/user",header:{accept:application/json,text/plain,*/*}},"statusText:""} ,but in my browser the url bring JOSN array !!. – Ebrahim Ze Aug 19 '16 at 20:36
  • Can you show me more code ? Because $resource return only an angular object to fetch data you have to use $ressource(url).query() for example. – Gerald Chablowski Aug 19 '16 at 23:43