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

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站