Home > Software design >  $http.get request does not work with API level 31
$http.get request does not work with API level 31

Time:11-23

I ask for your help for a problem that I encounter with IONIC 1. When I change the API level from 30 to 31 in the config.xml file:

this code is not working

$http.get($scope.url)
.then(function (success) {
  ...
}, function (error) {
$scope.errTXT = JSON.stringify(error);
});

returns a status of 0.

{ "data": null, "status": 0, "config": { "method": "GET", "transformRequest": [ null ], "transformResponse": [ null ], "url": "https://xxxxxxxxxxxxxxxxxx", headers: { "Accept": "application/json, text/plain, /" } }, "statusText": "" }

I don't understand why the result of http is null

CodePudding user response:

Did you remove the "android" folder and add it again?

ionic cordova platform remove android
ionic cordova platform add android

CodePudding user response:

Status code 0 usually means a CORS error.

You can read about Ionic CORS errors here.

Essentially, it is likely a misconfiguration on your server headers which are causing your Android app to throw the status code 0.

If you are using a development environment (e.g. localhost:4200) then you can add the following to your config.xml which should allow you to run it without needing a HTTPS:

<preference name="hostname" value="localhost" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />
  • Related