AngularJS POST到PHP失败不一致

I have been battling with a problem for quite a while and would like some outside input as to what could be causing my POST calls to fail inconsistently.

I have a web dashboard that uses AngularJS 1.4.8, and it sends POST calls to various PHP scripts to update a MySQL database.

The issue I'm having is that the success isn't always called and sometimes I have to trigger the POST again and then it will work

Sometimes it works first time.. other times it might take 2 attempts. I have tried using the .error( to call the function again but this can end up in an loop

Here is an example of a POST call

        $http({
            method: 'POST',
            url: $scope.URL+"SIVisitor.php",
            data: {
                "Value1": $scope.NewVisitorFirstname,
                "Value2": $scope.NewVisitorSurname,
                "Value3": $scope.NewVisitorEmail,
                "Value4": $scope.NewVisitorValue4,
                "Value5": $scope.NewVisitorValue5,
                "Value6": $scope.NewVisitorValue6
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        }).success(function(response) {
                // DO STUFF HERE
        });

Then I receive the information in a PHP file like below:

<?php

if($_SERVER["HTTPS"] == "on")
{

$data = json_decode(file_get_contents('php://input'), TRUE);

$Value1 = $data["Value1"];
$Value2 = $data["Value2"];
$Value3 = $data["Value3"];
$Value4 = $data["Value4"];
$Value5 = $data["Value5"];
$Value6 = $data["Value6"];

// ENTER INTO THE DATABASE

}
else {
}
?>

If its not going to work then it errors instantly. GET requests seem to work much better but I can't use them to send lots of form data

Other things that might help:

  • Webserver is Linux based using Apache

  • PHP 7.2 FastCGI (Although the same problem happened on 5.6)