Angularjs将数据发送到php

时间:2018-03-02 17:54:45

标签: php angularjs post

我有一个angularjs表,其中包含从mysql数据库收集的数据,我尝试做一个angularjs函数,它向PHP文件发送一个post请求以删除所选行,但它似乎没有用。

这是显示表并调用Angularjs removeUser函数的php代码(eliminarUsuario是removeUser函数):

echo "
    <div class='adminpanel'>
        <table border=\"0\">
            <tr>
                <th translate='BUTTON_USERNAME'></th>
                <th translate='BUTTON_NAME'></th>
                <th translate='BUTTON_LAST_NAME'></th>
                <th translate='BUTTON_ACTION'></th>
            </tr>
            <tr ng-repeat=\"x in dbusers | orderBy : 'Nombre' \">
                <td>{{x.cod_usuario}}</td>
                <td>{{x.Nombre}}</td>
                <td>{{x.Apellidos}}</td>
                <td>
                    <button  name='edit' value='{{x.cod_usuario}}' class='edit fa fa-pencil' ng-click=\"debuguear('{{x.cod_usuario}}')\"></button>
                    <button  name='eliminar' value='{{x.cod_usuario}}' ng-click=\"eliminarUsuario('{{x.cod_usuario}}')\" class='delete fa fa-remove'></button>
                 </td>
            </tr>
        </table>
    </div>
";

}

我使用这个Angularjs函数来做$ http帖子:

$scope.eliminarUsuario = function(user){
    $http.post('https://webUrl.../eliminarusuario.php', {usu: user});
    $state.go($state.current, {}, {reload: true});
};

然后它应该在PHP文件中执行此操作:

require "config.php";
$con = mysqli_connect($server, $username, $password, $dbname);
$datospost = file_get_contents("php://input");
$peticion = json_decode($datospost, true);
$user = $peticion->usu;
$consulta = "DELETE FROM 'Usuario' WHERE 'cod_usuario' = '$user'";
mysqli_query($con, $consulta);
mysqli_close($con);
header('Location: https://webUrl.../index.php');

0 个答案:

没有答案