Javascript 在xml中使用soap请求获取xml响应
我使用Javascript 在xml中使用soap请求获取xml响应,javascript,angularjs,xml,soap,ionic-framework,Javascript,Angularjs,Xml,Soap,Ionic Framework,我使用Ionic中的AngularJs和soap方法发出请求,我的响应是XML。请求后,控制台中出现错误;请帮帮我,我对AngularJs和Ionic了解不多 <WSTransferOfListOfWSListItem> <Message/> <Success>true</Success> <ProcessTime>748.8048</ProcessTime> <ReturnObject
Ionic
中的AngularJs
和soap方法发出请求,我的响应是XML。请求后,控制台中出现错误;请帮帮我,我对AngularJs
和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>
谢谢$soap服务将把服务器返回的xml反序列化为JavaScript对象。这就是为什么您会在控制台中看到
objectobject
。通过在控制台中展开对象,或在然后函数中设置断点,尝试检查对象。soap服务将服务器返回的xml反序列化为JavaScript对象。这就是为什么您会在控制台中看到objectobject
。通过在控制台中展开对象,或在然后函数中设置断点,尝试检查对象。执行此操作。。console.log(JSON.stringify(response))执行此操作。。console.log(JSON.stringify(response))如果你想测试和调试你的应用程序,你需要弄清楚这一点。尝试在常规浏览器中使用ionic serve运行它,这是最容易调试的。或者,对于Android,请遵循以下说明:。对于iOS,请参见以下问题:。当我使用console.log(response.ReturnObject.WSListItem.Text)时,我只会得到最后一条记录。如何获取所有记录?$soap似乎没有认识到ReturnObject是一个列表项数组。可能与这个问题有关:如果你想测试和调试你的应用程序,你需要弄清楚这一点。尝试在常规浏览器中使用ionic serve运行它,这是最容易调试的。或者,对于Android,请遵循以下说明:。对于iOS,请参见以下问题:。当我使用console.log(response.ReturnObject.WSListItem.Text)时,我只会得到最后一条记录。如何获取所有记录?$soap似乎没有认识到ReturnObject是一个列表项数组。可能与此问题有关:
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);
});
}
};
})
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);
});
}
};
})