0

I want to get the data from the webservice using angular js. pls help.. .

    $http(
                {
                    url: "xxx.asmx/GetLogin",
                        method: "GET",
                    params: { username: "admin", password: "admin" }
                }

                ).success(function (res) { alert(res); });

I get the result like this:

<?xml version="1.0" encoding="utf-8"?><string xmlns="xxxx">[{"UserID":2,"UserName":"Admin","UserType":1,"Password":"admin","Company":1,"CreatedDate":"\/Date(1411151400000)\/"}]</string>

How can i get the UserName and UserID from this string?

1

1 Answer 1

0

Do you have access you the server?

By seeing the asmx extension I assume you are using a .Net server.
You will want to return a json instead of an xml for easy processing on the client end.

Read here about returning a json from an asmx service.

You can technically reach the UserName and UserID by string manipulation (regex or split) - but that's not the correct way to do this.

Here's an extra UGLY and BAD way to extract data from your string:

var str = '<?xml version="1.0" encoding="utf-8"?><string xmlns="xxxx">[{"UserID":2,"UserName":"Admin","UserType":1,"Password":"admin","Company":1,"CreatedDate":"\/Date(1411151400000)\/"}]</string>';

var obj = str.split('[')[1].split(']')[0];
eval('var myRes = ' + obj + ';'); // ugly as hell
console.log(myRes.UserID);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.