Ajax请求发布没有功能


                    

我有一个简单的问题,但找不到错误。 也许你可以帮忙。 这是我的要求:</ p>

  $ http({
     网址:“ api / create_plane.php”,
     方法:“ POST”,
     数据:{
         planeKey:$ scope.editKey,
         planeSQLID:$ scope.editSQLID,
         planeLMID:$ scope.editLMID,
         planeAFID:$ scope.editAFID,
         planeVersion:$ scope.editVersion,
         planeLot:$ scope.editLot,
         planeStation:$ scope.editStation
     },
     dataType:'json'
})。success(函数(数据(状态,头文件,配置文件){
     console.log(data);
},函数(响应){
     console.log(response);
});
</ code> </ pre>

这是我的Php文件:</ p>

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

如果(空($ _POST ['planeLMID'])){
     对于($ i = 1; $ i <$ MAX_PLANES; $ i ++){
         如果(checkSQL($ i)){
             $ Planes [$ i] =新的createPlane($ i,$ db);
         }
     }
     回声json_encode($ Planes);
}
其他{
     对于($ i = 1; $ i <$ MAX_PLANES; $ i ++){
         如果($ Planes [$ i] ['planeSQLID'] == $ _POST ['planeSQLID']){
             回声“ HALLO”;
         }
     }
}
</ code> </ pre>

但是我什么时候都看不到“ Hallo” </ code>。 我需要你们的帮助。</ p>
     </ div>

展开原文

原文

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个回答


create_plane.php </ strong>文件中,当$ _POST ['planeLMID']为空时,您尝试使用空的$ Planes数组。 </ p>

因此,无论您是否通过POST接收数据,每次都需要获取$ Planes数组。
请参阅修改后的 create_plane.php </ strong> </ p>

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

对于($ i = 1; $ i <$ MAX_PLANES; $ i ++){
     如果(checkSQL($ i)){
         $ Planes [$ i] =新的createPlane($ i,$ db);
     }
}
回声json_encode($ Planes);

if(!empty($ _ POST ['planeLMID'])){
     对于($ i = 1; $ i <$ MAX_PLANES; $ i ++){
         如果($ Planes [$ i] ['planeSQLID'] == $ _POST ['planeSQLID']){
             回声“ HALLO”;
         }
     }
}
</ code> </ pre>
     </ div>

展开原文

原文

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";
        }   
    }
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐