weixin_33735077 2015-05-27 05:59 采纳率: 0%
浏览 54

在AngularJs中获取Ajax值

I'm passing the values in angularjs using $http to a url but I'm not able to get the values in AJAX file.

The following is my JS code:

$scope.insert = function() {
    var name = $scope.name;
    var pass = $scope.password;

    alert(name);
    alert(pass);
    $http({
        url : 'http://localhost/anguler/ajax.php?act=abc',
        data : {"pass":pass,"name":name},
        type : 'POST'
        }).success (function(resp){
            alert(resp);
        });
}

And this is the code in ajax.php:

if(isset($_REQUEST['act']) == 'abc')
{
    $user_name=$_POST['name'];
    $password=$_POST['pass'];
    echo $user_name.'**'.$password;
}

I'm not getting the values for $user_name and $password.

  • 写回答

1条回答 默认 最新

  • 衫裤跑路 2015-05-27 06:10
    关注

    Angular $http has another options, check it out:

    $http({
        method: 'POST',
        url: 'http://localhost/anguler/ajax.php?act=abc',
        data: {
            "pass": pass,
            "name": name
        }
    })
    

    Not type, but method. https://docs.angularjs.org/api/ng/service/$http#post

    Also, you can try to check passing values like isset($_REQUEST['pass']) == 'pass') { do stuff; }

    评论

报告相同问题?

悬赏问题

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