1

I'm making a request using AngularJs in Ionic with a soap method, my response is in XML. After request I have an error in the console; please help me I don't know much about AngularJs and Ionic.

<WSTransferOfListOfWSListItem>
    <Message/>
    <Success>true</Success>
    <ProcessTime>748.8048</ProcessTime>
    <ReturnObject>
      <WSListItem>
         <Selected>false</Selected>
         <Text>A KWIK FUEL</Text>
         <Value>KWIKFUEL</Value>
      </WSListItem>
      <WSListItem>
         <Selected>false</Selected>
         <Text>WILSON FARMS</Text>
         <Value>WILSON</Value>
      </WSListItem>
    </ReturnObject>
    <ResponseStatus>
       <Success>false</Success>
       <ProcessTime>0</ProcessTime>
       <MessageType>Warning</MessageType>
    </ResponseStatus>
    </WSTransferOfListOfWSListItem>

I'm getting that console result is [object Object], how to solve this issue? This is my code:

.controller('LoginCtrl', function($scope, $soap) {
$scope.user= {};
$scope.login = function() {
  if (typeof $scope.user.username == "undefined") {
   alert("Please enter username");
  } else if (typeof $scope.user.password == "undefined") {
   alert("Please enter password");
  } else {
       $soap.post("http://abc.asmx","AccountList",
        {UserName: $scope.user.username, Password: $scope.user.password, DeviceId: "E3-2A-6A-42-6D-C9-26-4F-10-A9-2C-3E-58-7D-00-2E-89-23-99-DD"})
       .then(function(response)
       {
           $scope.response = response.data;
           console.log(response); 
       });
  }
 };
})

Thank you

3 Answers 3

0

The $soap service will deserialize the xml returned by the server into a JavaScript object. That's why you see Object Object in the console. Try to inspect the object by expanding it in the console, or setting a breakpoint in the then function.

Sign up to request clarification or add additional context in comments.

3 Comments

you're going to need to figure that out, if you want to be able to test and debug your app. Try running it in a regular browser using ionic serve, that's the easiest to debug. Alternatively, for Android, follow these instructions: developer.chrome.com/devtools/docs/remote-debugging. For iOS, see this question: stackoverflow.com/questions/25689270/debug-ionic-app-on-ios.
When I'm console.log(response.ReturnObject.WSListItem.Text) then I'm getting only last record. How to get all records ?
it seems that $soap is not recognizing that ReturnObject is an array of list items. Might have something to do with this issue: github.com/andrewmcgivery/angular-soap/issues/23
0
Finally, I have done this using $http request and save response in local directory then call this local file(js/AccountList.xml).I have converted XML to JSON using xml2json.js.
.controller('LoginCtrl', function($scope, $http) {

$scope.user= {};
$scope.login = function() {
  if (typeof $scope.user.username == "undefined") {
   alert("Please enter username");
  } else if (typeof $scope.user.password == "undefined") {
   alert("Please enter password");
  } else {
       $http.post("js/AccountList.xml","AccountList",
              {UserName: $scope.user.username, Password: $scope.user.password, DeviceId: "E3-2A-6A-42-6D-C9-26-4F-10-A9-2C-3E-58-7D-00-2E-89-23-99-DD"})
             .then(function(response)
             {
                var x2js = new X2JS();
                var aftCnv = x2js.xml_str2json(response.data);
                var jsonResult = JSON.stringify(aftCnv.WSTransferOfListOfWSListItem.ReturnObject);
                console.log("========jsonResult========" + jsonResult);
       });
  }
 };
})

Comments

0

do this.. console.log(JSON.stringify(response))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.