1

これは私のangularjsコードです。配列またはjsonタイプの形式で取得できないコンソールプットで応答を取得しています

angular.module('user', ['ngResource']).

config(function($httpProvider){
    $httpProvider.defaults.headers.common['Accept'] = "application/json"
})
    .factory('loginUser', function($resource){
    alert("hello amit we done it");
   var user=$resource('http://localhost/testtext/index.php/user/login', {}, {
           login: {method:'POST'}}

    );
        console.log(user.login({"user": {"email":"prashant@gmail.com","password":"weldone"}}));
});

コンソール出力

Resource {user: Object, $resolved: false, $then: function, $get: function, $save:    function…}
$resolved: true
$then: function (b,g){var j=e(),h=
User: Array[1]
0: Object
address: "Noida"
city: "Mathura"
clientid: "clint000000000000009"
country: "India"
email: "prashant@gmail.com"
flag: "0000000000"
fname: "Sushil"
id: "users000000000000041"
lname: "Kumar1"
password: "ee486c2fa50a03b53982cba45ef045c2"
reset_pw_token: ""
session: Object
auth_token: "a1054379e166a085f4f331074c36b6d7"
created_by: null
created_on: null
id: "usaut000000000000187"
scope: "a:11:  {i:0;s:19:"user/changepassword";i:1;s:11:"user/logout";i:2;s:12:"role/getrole";i:3;s:17:"ro  le/getprivilege";i:4;s:13:"category/save";i:5;s:13:"message/reply";i:6;s:16:"message/classify";i:7;s:12:"message/read";i:8;s:12:"message/list";i:9;s:12:"tag/messages";i:10;s:8:"tag/l ist";}"
updated_by: null
updated_on: "2013-09-03 19:30:52"
user_id: "users000000000000041"
__proto__: Object
state: "UP"
__proto__: Object
length: 1
__proto__: Array[0]
__proto__: Resource
4

1 に答える 1

1

成功と失敗の関数を使用する必要があります

user.login({"user": {"email":"prashant@gmail.com","password":"weldone"}},
function(data){
      console.log(data[0]) //or data.User[0] or data.user[0] depending upon on your json.
    },
function(error) {
    console.log(error)   // Error details
    })
于 2013-09-03T14:18:39.120 に答える