Web Services, Part IV: WebService Behavior's Objects, Properties, and Events: The onresult Event Handler - Doc JavaScript | WebReference

Web Services, Part IV: WebService Behavior's Objects, Properties, and Events: The onresult Event Handler - Doc JavaScript


Web Services, Part IV: WebService Behavior's Objects, Properties, and Events

The onresult Event Handler

The onresult event fires when a result has been received from a remote Web service using the WebService behavior. It is only available to objects in the document to which the WebService behavior is attached. Here is an example that shows how to specify this event handler:

<DIV ID="service" STYLE="behavior:url(webservice.htc)"
   onresult="onWSresult()">

You cannot specify both an onservice event handler and a function callback for the callService() method. If you do specify them both, the onresult event will not fire.

All properties of the event object are generally available in the Result object. They are:

When result.error is true (an error occurred), the errorDetail object is available as a property of the result object:

The following example shows how to use the onresult event handler:

<SCRIPT LANGUAGE="JavaScript">
var iCallID;
function init() {
  service.useService("/services/math.asmx?
    WSDL","MyMath");
  iCallID = service.MyMath.callService
    ("add",5,6);
}
function onWSresult() {
  if((event.result.error)&&(iCallID==event.result.id)) {
    var xfaultcode   = event.result.errorDetail.code;
    var xfaultstring = event.result.errorDetail.string;
    var xfaultsoap   = event.result.errorDetail.raw;
    document.writeln("ERROR. Method call failed!");
    document.writeln("Call ID:" + iCallID);
    document.writeln("Fault Code:" + xfaultcode);
    document.writeln("Fault String:" + xfaultstring);
    document.writeln("SOAP Data:" + xfaultsoap);
  } else if(event.result.error == false) {
      document.writeln("Result received
      without errors!");
    }
}
</SCRIPT>
<BODY onload="init()">
<DIV ID="service" style="behavior:url(webservice.htc)"
  onresult="onWSresult()">
</DIV>
</BODY>

Next: A Final Word

http://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: December 17, 2001
Revised: December 17, 2001

URL: http://www.webreference.com/js/column99/7.html