Ionic v1 respond with status code -1 when testing on device

I am using ionic v1. I have configured my wamp server to listen for 8100 port and header(‘Access-Control-Allow-Origin: *’).

I can post to server when testing in browser using ionic serve but when testing on device request fails with status code -1 and no message.

Object {data: null, status: -1, headers: function, config: Object, statusText: ""}
config: Object
data: null
headers: function (name) {
status: -1
statusText: ""
__proto__: Object

I have found several similar issue over internet dated couple of month old. However there seems no answer on what is the real reason behind this behavior.

The project we are working on have been started using AngularJS and ionic v1. For the MVP it would be to much a work to switch over to more stable ionic2/angular2. While Ionic team encourages developers to move to higher version I have found clear statements from team that Ionic v1 will be maintaned for long time and it is still safe to use old version. However this issue makes us feel unconfortable about using v1.

Did you remote debug the problem on the device already? Follow these instructions here to debug the problem in Safari dev tools (for iOS): https://ionic.zone/debug/remote-debug-your-app#ios or in Chrome dev tools (for Android=: https://ionic.zone/debug/remote-debug-your-app#android Look at the console and network tabs for errors.

Yes, I have done that. In console I get:

POST http://localhost:8100/ionic_jigup/users/login  ionic.bundle.js:25005
(anonymous function) ionic.bundle.js:25005
sendReq ionic.bundle.js:24798
$http.serverRequest ionic.bundle.js:24508
processQueue ionic.bundle.js:29132
(anonymous function) ionic.bundle.js:29148
Scope.$eval ionic.bundle.js:30400
Scope.$digest ionic.bundle.js:30216
Scope.$apply ionic.bundle.js:30508
listener ionic.bundle.js:63577
triggerEvent ionic.bundle.js:822
tapGesture ionic.bundle.js:1718
detect ionic.bundle.js:1400
bindDomOnTouch ionic.bundle.js:949

Error message from $http promise returns{data: null, status: -1, headers: function, config: Object, statusText: ""}

in network tab I have status failed, type pending and no response.

The same happens when making calls to server. I can make call from browser testing but can not from device.

What is the code to make these requests?

$scope.testhttp = function(){
			console.log('lets test');
			$http({
					method: 'POST',
					url: '/app/test',
					data: {
						result: 'lalalala'
					}
				}).then(function(resp){
					console.log(resp.data);
				}, function(err){
					console.log(err)
				})
		}

and I have also registered some $http interceptors:

/* ====================  Base Interceptor ========================= */
(function () {
	angular
	  .module('jigup')
	  .config(function ($httpProvider) {
		$httpProvider.interceptors.push(apiInterceptor);
	   });

	// api url prefix
	var API_URL = 'http://www.mydomain.com';

	function apiInterceptor ($q) {
	  return {
		request: function (config) {
		  var url = config.url;

		  // ignore template requests
		  if (url.substr(url.length - 5) == '.html') {
			return config || $q.when(config);
		  }

		  config.url = API_URL + config.url;
		  return config || $q.when(config);
		}
	  }
	}
})();
/* ====================  PHP post ========================= */
(function(){
	angular
		.module('jigup')
		.config(function($httpProvider) {
		   $httpProvider.defaults.headers.post['Content-Type'] = 'application/json';
			var param = function(obj) {
			return JSON.stringify(obj);
		  };
		 
		  $httpProvider.defaults.transformRequest = [function(data) {
			return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
		  }];
		})
})();

Please just ask what information you need to understand issue, I will provide with it. We are really stuck with this one.

The code you posted doesn’t POST to /users/login which is part of the error.
Does it work when you get rid of the Interceptors?

If this is iOS, I suspect the issue is caused by not using TLS. Make all your requests use https urls, not http.

Sorry I gave different example. The idea is that POST does not work what ever endpoint is, even localhost. app/test and users/login both are succesful POST when posting from browser but return -1 status from device.

Tried without interceptors but got the same error.

No it is Android. Using HTC Desire 601 device

Create a new project, put only the HTTP request in there and see if you get the same error. If so, use dev tools to figure out what is going on, if not then find out what is different in our actual project.

Idid as you suggested. On running ionic build android I recieved error

Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: C:\Users\User\AppData\Local\Android\Sdk\tools\templates\gradle\wrapper

So I followed the questions/answer that I could find for this but found different problem. In android studio->tools->sdk manager my android sdk location is listed as C:\Users\User\AppData\Local\Android\Sdk but when I open the folder C:\Users\User there is no subfolder AppData.

You have to click the path in explorer and just type “AppData” - the folder is hidden by default for users. (And obviously “user” has to be replaced by your user name)

So I made new blank project. But still get the same issue. But it actually could be something with android SDK - before updating sdk I could make POST from browser, now also from browser I get -1 status code.

Running the Ionic app in the browser has no connection to the Android SDK at all.