spacer
Yehuda Shiran November 21, 2001
Handling the event.result Object
Tips: November 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
One of the two ways to call a Web service in Internet Explorer is without a callback handler. Here is an example that calls the add method with two arguments, intA and intB:

iCallID = service.MyMath.callService("add", intA, intB);
In this case, you need to specify the onresult event handler:

<DIV id="service" 
     STYLE="behavior:url(webservice.htc)" 
     onresult="onWSresult()">
The event handler onWSresult() first checks to see if there was an error during the Web service call:

  if (event.result.error)
Notice that the result object is a property of the event object. The event handler also checks that the event ID, as it came from the Web service, is identical to the ID returned by the callService() funtion:

  if (iCallID==event.result.id)
With these two checks you can write an event handler that processes the result object, checks for errors and matching IDs, and prints the result value. Here is a Microsoft example:

<SCRIPT language="JavaScript">
<!--
// All these variables must be global,
// because they are used in both init() and onresult().
var iCallID = 0;
var intA = 5;
var intB = 6;

function init() {
  service.useService("/services/math.asmx?WSDL","MyMath");
  iCallID = service.MyMath.callService("add", intA, intB);
}

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;
  } else if((!event.result.error) && (iCallID == event.result.id)) {
           alert(intA + ' + ' + intB + ' = ' + event.result.value);
         } else {
           alert("Something else fired the event!");
         }
}
// -->
</SCRIPT>
<BODY onload="init()">
<DIV id="service" 
     STYLE="behavior:url(webservice.htc)" 
     onresult="onWSresult()">
</DIV>
</BODY>

People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends