dovhpmnm31216 2018-07-11 00:09
浏览 39

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)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大