Http get Request always must fired twice to work? Help pls

@mich356c
Well i tried to test my new code now on a real android device with a real apk. But the http request doesnt work anymore. So i debugged it in firefox and got this output of the console whitch i think is the problem that causes my login issue on devices:

Request denied: … CORS-Header ‘Access-Control-Allow-Origin’ missing

How can i resolove this issue?

EDIT: Ok i can login now in Browser by adding this to my api.php file:

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);
}

Refering to this link: Posting data from Ionic app to PHP server – Nikola Brežnjak blog and this forum thread: $http No 'Access-Control-Allow-Origin' problem on POST - #6 by Hitman666

But i still cant login on my real device…