drj26159 2015-12-10 14:15
浏览 13
已采纳

PHP从角度http请求中获取INT

How to get an int-value from an $http-request in PHP ?

I´m trying to send a http request from an Angular app but i´m not able to get the value of the sent `id`` parameter into my PHP variable $id.

I tried several methods like:

$id = $_POST['id'];

or

$id = $connection->real_escape_string(isset($_POST['id']) ? $_POST['id'] :'');

in my PHP but nothing works...

This is my function to send the $http request

function removeFriend( id ) {
        var request = $http({
            method: "delete",
            url: "php/deleteFriend.php",data: $.param({'id':id}),
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        });
        return( request.then( handleSuccess, handleError ) );
    }
  • 写回答

2条回答 默认 最新

  • du1843 2015-12-10 14:26
    关注

    The problem was the method of the $http request. you have to use POST so PHP can get the values with the $_POST['id'] method.

    So here is the code that works:

    Javascript

    function removeFriend( id ) {
            var request = $http({
                method: "post",
                url: "php/deleteFriend.php",data: $.param({'id':id}),
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            });
            return( request.then( handleSuccess, handleError ) );
        }
    

    PHP

    $id = $_POST['id'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度