dtcpvz8162 2015-09-21 07:30
浏览 63

没有使用angular.js获取查询字符串值

I have a URL like this http://localhost/phpdemo/edit_data.php?edt_id=1. Here I need the query string value which is 1. By using Angular.js, I am getting the following output in browser's console.

id is : Object {}

My code is given below.

update.js:

var app=angular.module("edit_data", []);
app.controller("updateController",function($scope,$http,$location){
    $scope.errors = [];
    $scope.msgs = [];
    var id=$location.search();
    console.log("id is :",id);
    $http.get('js/edit.php',{"user_id":$location.hash()}).success(function(response){
        console.log('response',response);
    });
    $scope.update_data=function(){
        $http.post('js/update.php',{"first_name":$scope.first_name,"last_name":$scope.last_name,"city":$scope.city}
        ).success(function(data, status, headers, config){
            if(data.msg!=''){
            $scope.msgs.push(data.msg);
            }else{
                $scope.errors.push(data.error);
            }
        }).error(function(data, status) { // called asynchronously if an error occurs
               // or server returns response with an error status.
              $scope.errors.push(status);
        });
    }
});

Please help me to resolve this issue.

  • 写回答

2条回答 默认 最新

  • dtrb96410 2015-09-21 07:34
    关注

    This $location.search(); return an array, so

    console.log("id is :",id[0]);
    

    Can you try with above.

    UPDATE:

    $location.search()['edt_id']
    

    It must return the value 1

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!