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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

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 >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji