0

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)

  • The `.success` method is [deprecated and removed from AngularJS V1.6](https://stackoverflow.com/questions/35329384/why-are-angularjs-http-success-error-methods-deprecated-removed-from-v1-6/35331339#35331339). If you are sending json the content type should be `application/json` not `x-www-form`. – georgeawg Jul 11 '18 at 01:00
  • What is the error when the POST request fails? – georgeawg Jul 11 '18 at 01:04
  • Thanks George, I did read about it being deprecated but didn't think it would affect me using 1.4.8. I've just changed the content type to application/json and it seems to be working much better now! No fails after 20+ attempts Thank you so much – VisitUs Reception Jul 11 '18 at 01:06
  • I spoke too soon.... It's still failing – VisitUs Reception Jul 11 '18 at 05:06
  • You sould give us the error to help you. – MrWook Jul 11 '18 at 05:15
  • The error that comes back is simply "null" – VisitUs Reception Jul 11 '18 at 05:23
  • When I run the application in the IOS Simulator I get 1 of two errors so I'm leaning towards it being an issue with the web server - NSURLConnection finished with error - code -1100 - NSURLConnection finished with error - code -1005 – VisitUs Reception Jul 11 '18 at 05:36

0 Answers0