spacer
Yehuda Shiran November 22, 2001
Handling the result Object
Tips: November 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

One of the two ways to call a Web service is with a callback handler. Here is an example that calls the add method with two arguments, intA and intB:

iCallID = service.MyMath.callService(mathResults,"add", intA, intB);
The event handler mathResults() accepts the result object as its sole parameter:

  function mathResults(result)
The name of the parameter can be different than "result". Inside, it checks whether there were errors during the call to the Web service:

  if (result.error) { .... }
Use this check to write an event handler that processes the result object and prints the error details (if any) as well as 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(mathResults, "add", intA, intB);
}

function mathResults(result) {
  if(result.error) {
    var xfaultcode   = result.errorDetail.code;
    var xfaultstring = result.errorDetail.string;
    var xfaultsoap   = result.errorDetail.raw;
  } else{  
      alert(intA + ' + ' + intB + " = " + result.value);
    }
}
// -->
</SCRIPT>
<BODY onload="init()">
<DIV ID="service" style="behavior:url(webservice.htc)">
</DIV>
</HTML>

People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint