Use JavaScript to call Web Services

Source: Internet
Author: User

If you are using Microsoft IE 5 or later, you can use the behavior/html-component "WebService" to access a web service. the "WebService" behavior communicates with Web Services over HTTP using Simple Object Access Protocol (SOAP ).

To use the "WebService" behavior, you must attach it to an element using the style attribute, as follows:

<Div id = "giveitaname"
Style = "behavior: URL (WebService. HTC)"> </div>

A complete example taken from the Microsoft Web site is as follows:

<HTML>
<Head>
<Script language = "JavaScript">
VaR icallid;

Function Init ()
{
Service. useservice
("Http://myserver.com/services/myservice.asmx? WSDL ",
"Servicename ");
}

Function onmyresult ()
{
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;

// Add code to output error information here
Alert ("error ");
}
Else
{
Service. innerhtml = "The method returned the result :"
+ Event. Result. value;
}
}
</SCRIPT>
</Head>
<Body onload = "Init ();">
<Br>
Enter a value <input type = 'text' id = 'param1'>
<Br>
<Button onclick = 'icallid = service. servicename. callservice
("Procedurename", param1.value); '> call a web method </button>
<Div id = "service"
Style = "behavior: URL (WebService. HTC )"
Onresult = "onmyresult ();">
</Div>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.