App works fine on browser platform but doesn't work in both real and emulator android device!

Hi every one!

I develop an app that post and get data from external PHP server. When i run it on Chrome (ionic serve), it works fine, I can get data to list, insert new data, update and delete data…everything is ok. But when I run it on my phone, it doesn’t get any data from my external server and all of other functions (insert, update, delete) don’t work.

Data is returned from my server with JSON format. Example a getting list function:

if (isset($_SERVER['HTTP_ORIGIN'])) {
	        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
	        header('Access-Control-Allow-Credentials: true');
	        header('Access-Control-Max-Age: 86400');    // cache for 1 day
	    }
	 
	    // Access-Control headers are received during OPTIONS requests
	    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
	 
	        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
	            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
	 
	        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
	            header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
	        exit(0);
	    }
$query = $this->db->query('My sql code');
echo json_encode($query->result_array());

And when I run app in Ionic View, it works fine too.

Please help me! Thank you very much!