Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

angularjs having issues accessing object returned by ajax call

Posted on 2014-03-26
1
Medium Priority
?
689 Views
Last Modified: 2014-03-26
I can successfully console.log the response from my ajax request, but I don't know how to access the object.  In the examples I have seen, they just access the properties.  I have even tried to parse it.

                var url = 'myservoce.svc/CancelSelections';
                $http({ method: 'POST', url: url })
                    .then(function(response) {
                        console.log(response);
                        console.log(response.data);
                        console.log(response.data.ExportShareOutputModel);
                        console.log(response.data.success);
                    }, function (response) {
                        alert("Fail CancelSelections=" + response);
                    });


When I run this code, I get

console.log(response);
Object {data: "<ExportShareOutputModel xmlns="http://schemas.data…><success>true</success></ExportShareOutputModel>", status: 200, headers: function, config: Object}

console.log(response.data);
<ExportShareOutputModel xmlns="http://schemas.datacontract.org/2004/07/MyProj.WebServices.ExportShare" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ErrorMessage i:nil="true" xmlns="http://schemas.datacontract.org/2004/07/Fmg.Cti.Utilities.Patterns.MVP.Model"/><IsValid xmlns="http://schemas.datacontract.org/2004/07/Fmg.Cti.Utilities.Patterns.MVP.Model">true</IsValid><message/><success>true</success></ExportShareOutputModel>



                        console.log(response.data.ExportShareOutputModel);
undefined
                        console.log(response.data.success);
undefined
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39956799
Yes response.data is a string, an XML string
Test page : http://jsfiddle.net/ssL5r/

var response = {data: "<ExportShareOutputModel xmlns=\"http://schemas.data\"><success>true</success></ExportShareOutputModel>", status: 200, headers: function(){}, config: {}};
var data = response.data;
var ExportShareOutputModel = jQuery.parseXML(data);
var success = $("success",ExportShareOutputModel).text();

alert(success);

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question