AngularJS-ionic framework http.get error

674 views Asked by At

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', '*')

0

There are 0 answers