0

I'm trying to use http.get with ionic framework. I've made a API REST with Slim framework.

When i try this in my services.js:

$http({ method: 'GET', url: 'http://localhost/API_Rest/api.php/user/jean/pass/jeanvaljean' }).success(function (data) {
                console.log(data);
});

I've this error:

Error: Unexpected request: GET http://localhost/API_Rest/api.php/user/jean/pass/jeanvaljean
No more request expected
    at $httpBackend (angular-mocks.js:1211)
    at sendReq (ionic.bundle.js:18327)
    at $get.serverRequest (ionic.bundle.js:18043)
    at processQueue (ionic.bundle.js:21888)
    at ionic.bundle.js:21904
    at Scope.$get.Scope.$eval (ionic.bundle.js:23100)
    at Scope.$get.Scope.$digest (ionic.bundle.js:22916)
    at Scope.$get.Scope.$apply (ionic.bundle.js:23205)
    at HTMLButtonElement.<anonymous> (ionic.bundle.js:53457)
    at HTMLButtonElement.eventHandler (ionic.bundle.js:11713)

If you need more informations ask me.

Thank's!

EDIT: I've add this line before the GET: $httpBackend.whenGET(/.*/).passThrough();

And now i've this error:

XMLHttpRequest cannot load http://localhost/API_Rest/api.php/user?name=g&pass=ezg. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

EDIT 2: I've found the problem it was on my API, i've to specify the header : header('Access-Control-Allow-Origin', '*')

Kreepz
  • 139
  • 2
  • 13
  • Install a chrome extension: Rest client ,call the api from there to check if it returns data. – Sajal Jun 25 '15 at 17:24
  • Hi, i use Postman and the api return me this: http://img11.hostingpics.net/pics/749420PostmanGoogleChrome.jpg – Kreepz Jun 26 '15 at 05:55
  • Is this what it should return? What was the payload sent ? I dont see any request params in the Get here. – Sajal Jun 26 '15 at 06:06
  • Yeah this is the good return, i've write directly the params in the url. In this url (http://localhost/API_Rest/api.php/user/jean/pass/jeanvaljean) jean is param and jeanvaljean is a another param – Kreepz Jun 26 '15 at 06:11
  • see this answer: http://stackoverflow.com/questions/13760070/angularjs-passing-data-to-http-get-request – Sajal Jun 26 '15 at 06:21
  • You ll probably have to change the url to a relative path and send the request params as in the answer above. – Sajal Jun 26 '15 at 06:22
  • My new path is (http://localhost/API_Rest/api.php/user) and i use your answer for write my GET in my js but i've the same error... my get ($http({ url: '/API_Rest/api.php/user', method: 'GET', params: { name: name, pass: pw } });) – Kreepz Jun 26 '15 at 06:48

0 Answers0