weixin_33696822 2016-09-30 15:24 采纳率: 0%
浏览 22

Ajax请求发布没有功能

I have got a simple problem but cannot find the error. Maybe you can help. Here is my request:

$http({
    url:'api/create_plane.php',
    method: "POST",
    data: {
        planeKey: $scope.editKey,
        planeSQLID: $scope.editSQLID,
        planeLMID: $scope.editLMID,
        planeAFID: $scope.editAFID,
        planeVersion: $scope.editVersion,
        planeLot: $scope.editLot,
        planeStation: $scope.editStation                   
    },
    dataType: 'json'
}).success(function(data, status, headers, config) {
    console.log(data);
}, function(response) {
    console.log(response);
});

This is my Php file:

$Planes = array();
$MAX_PLANES = 45;

if (empty($_POST['planeLMID'])) {
    for ($i = 1;$i < $MAX_PLANES;$i++) {
        if (checkSQL($i)) {
            $Planes[$i] = new createPlane($i,$db);
        }
    }
    echo json_encode($Planes);   
}
else {
    for ($i = 1;$i < $MAX_PLANES; $i++) {
        if ($Planes[$i]['planeSQLID'] == $_POST['planeSQLID']) {
            echo "HALLO";
        }   
    }
}

However I don't see "Hallo" at any time. I need your help guys.

  • 写回答

1条回答 默认 最新

  • 笑故挽风 2016-09-30 15:57
    关注

    In create_plane.php file you are trying to use empty $Planes array when $_POST['planeLMID'] is empty.

    So you need to fetch $Planes array each time regardless of whether or not you are receiving data by POST. See modified create_plane.php

    $Planes = array();
    $MAX_PLANES = 45;
    
    for ($i = 1;$i < $MAX_PLANES;$i++) {
        if (checkSQL($i)) {
            $Planes[$i] = new createPlane($i,$db);
        }
    }
    echo json_encode($Planes);   
    
    if(!empty($_POST['planeLMID'])) {
        for ($i = 1;$i < $MAX_PLANES; $i++) {
            if ($Planes[$i]['planeSQLID'] == $_POST['planeSQLID']) {
                echo "HALLO";
            }   
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致