Comments (7)
It took me a while to get my mind wrapped around this one, but I do understand now...
The SOAPResponse object is only available within the success and error functions of the $.soap options. When using promises you get back (data, textStatus, jqXHR) so you need to do something like:
// untested code:
contactService.findContacts()
.done(function(data, textStatus, jqXHR) {
console.log($.parseXML(data).firstChild);
});
Hope this helps...
from jquery.soap.
Thanks @doedje,
This is what i'm doing now to get SOAP result as JSON
contactService.findContacts()
.done(function(data, textStatus, jqXHR) {
// TODO use JsonPath to avoid using multiple firstChild
// Depth = data(document).firstChild(Soap:Envelope).firstChild(Soap:Body).firstChild(Soap:Body).firstChild(Soap:Response)
var jsonResponse = $.xml2json(data.firstChild.firstChild.firstChild);
console.log(jsonResponse.GetContactsResponse.ListContacts);
});
Very ugly, specially when I make multiple calls of firstChild to get the response ...
from jquery.soap.
You could also use jquery to parse the XML.
With the following SOAPResonse:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns:return xmlns:ns="http://localhost/">
<ns:status>STATUS_OK</ns:status>
<ns:message>FAKE SOAP RESPONSE!</ns:message>
</ns:return>
</soap:Body>
</soap:Envelope>
You could do like this:
contactService.findContacts()
.done(function(data, textStatus, jqXHR) {
console.log($(data).find('ns\\:status').text());
});
In your case:
var jsonResponse = $.xml2json($(data).find('GetContactsResponse').html());
Just to let you know! Good luck with coding!
from jquery.soap.
This is old, but looking at how SoapResponse does it, it's using the xhr response instead of data, not sure if that makes any difference
var SOAPResponse = function(status, xhr) {
this.typeOf = "SOAPResponse";
this.status = status;
this.headers = xhr.getAllResponseHeaders().split('\n');
this.httpCode = xhr.status;
this.httpText = xhr.statusText;
this.content = (xhr.responseXML === undefined) ? xhr.responseText : xhr.responseXML;
this.toString = function(){
if (typeof this.content === 'string') {
return this.content;
}
if ($.isXMLDoc(this.content)) {
return SOAPTool.dom2string(this.content);
}
throw new Error("Unexpected Content: " + $.type(this.content));
};
this.toXML = function(){
if ($.isXMLDoc(this.content)) {
return this.content;
}
return $.parseXML(this.content);
};
this.toJSON = function(){
if ($.xml2json) {
return $.xml2json(this.content);
}
warn("jQuery.soap: Missing JQuery Plugin 'xml2json'");
};
};
from jquery.soap.
the difference is this: you can either use the success
option or the promise function .done
to deal with the response, just a matter of personal preference I guess:
$.soap({
// blah, blah, all kind of options here... like url, data, etc...
success: function(SOAPResponse) {
// here you get back the SOAPResponse object you copied above
// with it's properties and functions, like toJSON() for instance...
console.log(SOAPResponse.toJSON());
}
});
the OP of this issue wanted to use the Promise returned by
$.soap({
// blah, blah, all kind of options here... like url, data, etc...
}).done(function(data, textStatus, jqXHR) {
// here you get back `data, textStatus, jqXHR` so you can do:
console.log(data);
});
Hope that clears the confusion a bit....
from jquery.soap.
I think you misunderstood. I was referring to the difference between:
$.xml2json(data);
vs
var content = (xhr.responseXML === undefined) ? xhr.responseText : xhr.responseXML;
$.xml2json(content);
from jquery.soap.
Ah I see, I misunderstood indeed, I thought your question was somehow related to this issue, but if it does I don't understand how...
But the difference is unclear to me. $.soap is open source project with a handful of people collaborating to it in the past years. This got introduced at some point around the 0.10.0 version by Zach if I recall this correctly, I hope it was for the best.... =]
from jquery.soap.
Related Issues (20)
- Posible enhancement? - $.soap in Angular (or Angular 2) HOT 4
- cors error when running code HOT 2
- Please disable the useless OPTIONS request by default HOT 3
- Setting timeout possible? HOT 1
- Syntax error in latest releae? HOT 1
- my soap method doesnt work HOT 4
- Undefined request in beforeSend() HOT 5
- Are you planning to publish the last version on npm registry?? HOT 1
- Support for Bare parameter style HOT 8
- Namespace HOT 3
- getting Jquery is not defined error HOT 4
- 想加入xml头信息,用$.soap()怎么做? HOT 1
- Any way to do synchronous calls? HOT 2
- Calling “$.soap” with React.js HOT 3
- HTTPHeaders are not provided with request? HOT 3
- Success function doesn't get run on success HOT 5
- TypeError: $.soap(...).done is not a function HOT 2
- Created url don't match tomcat AXIS servlet HOT 2
- can call wcf svc asp.net with this library? HOT 5
- How to convert the following PHP SOAP call to work in your jquery.soap HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery.soap.