How the heck can jQuery $.get, $.post and get desired results but angular can't $http.get, $http.post? Why is the origin policy not working for angular but for jquery?
Laravel backend, angular front-end. I'm considering just using jQuery because it doesn't prevent CRUD actions from happening on the client-side.
I configured $http and $httpProvider...
.run(function($http){
$http.defaults.headers.common['Access-Control-Allow-Origin'] = "*";
$http.defaults.headers.common['Access-Control-Allow-Methods'] = "GET, POST, PUT, DELETE, OPTIONS";
$http.defaults.headers.common['Access-Control-Allow-Headers'] = "Authorization";
})
.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
})
And laravel is sending back the appropriate header...
App::after(function($request, $response)
{
// header('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Origin', '*');
});
So the weird thing is angular $http cannot get anything back from the server and produces this error:
XMLHttpRequest cannot load http://0.0.0.0:8000/api/test. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
But jQuery $.get and $.post work correctly!
$.post('http://0.0.0.0:8000/api/test', function(resp){
console.log(resp);
});
What am I doing wrong here?