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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 求数学坐标画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站