doedje / jquery.soap

This script uses $.ajax to send a SOAP:Envelope. It can take XML DOM, XML string or JSON as input and the response can be returned as either XML DOM, XML string or JSON too.
352 stars 147 forks source link

How do you extract the result when using JSON? #5

Closed Velocedge closed 11 years ago

Velocedge commented 11 years ago

In the soap response I'd like to use var rtn = SOAPResponse.toJSON() and extract the returned value but don't know how to reference it. My action/method is LMSLaunch. It appears that it's under rtn.soap:Body.LMSLaunchResponse.LMSLaunchResult but I'm unable to reference it that way. What am I doing wrong... again! ;-)

doedje commented 11 years ago

I guess you are developing in IE. Try installing a different browser (Chrome or FireFox with Firebug) so you can proper debug/log your application. Simply console.log(SOAPResponse.toJSON()); and SEE what you got! With IE's Developers Tools, you will only get back a [object Object] which tells you nothing...

I did not check this, but I think you should leave out the soap:Body... what SOAPResponse.toJSON() returns is the contents of the soap:Body...

Velocedge commented 11 years ago

With IE I’m using VS 2010 and VS 2012 as my debugger and can see the properties of the response fine. That’s how I knew the first property was soap:Body as well as the LMSLaunchResponse and LMSLaunchResult properties under it. It “looks” like I should be able to reference them but I’m guessing the : is messing things up for IE.

However, it is interesting that in Chrome and FF I can get the value with rtn.Body.LMWLaunchResponse.LMSLaunchResult but in IE (8, 9, or 10) it’s undefined... everything’s basically undefined.

Velocedge commented 11 years ago

Found it... In IE you have to do rtn[“soap:Body”].LMSLaunchResponse.LMSLaunchResult

doedje commented 11 years ago

Interesting results... I will do some testing and see if I can come up with something so you can access the data in the same way for all browsers...

(What is your IE's version? I have IE9 here)

Velocedge commented 11 years ago

No worries... have it handled.

var soapHeader = ‘’; if (IE) soapHeader = 'soap:’; method = ‘LMSLaunch’; var result = rtn[soapHeader + ‘Body’][method + ‘Response’][method + ‘Result’];

sr