spacer
Yehuda Shiran July 15, 2002
Calling Web Services from JavaScript
Tips: July 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
When you want to utilize your Web services, put them (asmx files) in a sub-directory of your Web server, such as c:\inetpub\wwwroot\Webreference. Then, when you access the services in your scripts, you refer to their directory as http://localhost/Webreference. For each Web service you utilize you need to have three JavaScript functions:

  • The init() function assigns a short name to the Web service URL
  • A function to call the Web service with the appropriate parameters
  • A function to display the results

For our add Web service, the function addNumbers() is invoked when the Add button is clicked. It calls the webservice behavior's callService() method. The parameters are: (i) the function that handles the result display, (ii) the Web service command, "add", (iii) the first number, and (iv) the second number:

  function addNumbers(a, b) {
    myWebService.simpleCalcWebService.callService(addResult, 
      "add", first.value, second.value);
  }
Similarly, for the IsPrime Web service, isPrimeNumber() is called when the Click here to check if prime button is clicked. It calls the Web service with three parameters: (i) the function to handle the result, isPrimeNumberResult, (ii) the Web service request, IsPrime, and (iii) the parameter expected by the Web service, testValue.value:

  function isPrimeNumber() {
    myWebService.isPrimeNumberWebService.callService(isPrimeNumberResult, 
      "IsPrime", 
      testValue.value);
  }
To learn more about JScript .NET, go to Column 112, JScript .NET, Part VI: Creating IE Web Services.


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 RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags