Hello folks!
I’m writing a very common topic, but I am desperate, wasted two days trying to make this work.
I’m on Chrome, trying to make my first Login/Register app and at the time of sending the data to the backend, i get the following error:
XMLHttpRequest cannot load http://192.168.1.133:8100/api/login. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access. The response had HTTP status code 500.
Ionic code:
$scope.data = "UserName"; // for example
$scope.register = function() {
var conAjax = $http.post('http://192.168.1.133/api/register', $scope.data);
conAjax
.success(function(respuesta){
console.log(respuesta.message);
})
.error(function(respuesta) {
console.log("error");
});
}
])
And the backend in Laravel, is simple:
public function login (Request $request) {
$inputArray = $request->all();
return response()->json(["message" => "Login: All Correct"]);
}
I don’t even do any operation, just return ‘Correct’.
To my config.xml I’ve added whitelist allowance to ALL (for testing):
<allow-navigation href="http://*/*" />
<allow-navigation href="*" />
<access origin="*"/>
In PHP Laravel I’ve disabled CORS, following a tutorial.
I’ve tried to add the <meta http-equiv=“Content-Security-Policy” …> tag, but only generates me errors.
And I keep getting this same error on Chrome console.
I just want to know if I am sending alright the params, for Login to the API.
It also doesn’t work Testing links like: https://requestb.in/ , where I can test GET/POST requests.
I don’t know what else I am missing…
On Windows 10, Ionic v1.
Thanks a lot!