Calling WebServices using JavaScript
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 ");
}< br> else
{< br> service. innerhtml = "The method returned the result:"
+ event. result. value;
}< BR >}< br>
enter a value
call a web method
style = "behavior: URL (WebService. HTC) "
onresult =" onmyresult (); ">
Source: http://weblogs.asp.net/Varad/archive/2004/06/14/155671.aspx
This is actually better.
Remote scripting in A. Net World
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnclinic/html/scripting11122001.asp
Scripting Web Services
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnclinic/html/scripting03132000.asp
There are many methods to call. But in general, it is divided into two categories:
1. Call method with return values: (this method can be used for any reverse return value)
<Script language = "JavaScript">
Function getdatal (URL ){
VaR XMLHTTP = new activexobject ("msxml2.xmlhttp. 4.0"); // create an XMLHTTPRequest object. msxml4.0 must support ["msxml2.xmlhttp. 4.0", "msxml2.domdocument. 4.0"]
XMLHTTP. Open ("get", URL, false, "", ""); // use http get to initialize HTTP requests
XMLHTTP. Send (""); // send an HTTP request and obtain an HTTP Response
Return XMLHTTP. responsexml; // get the XML document
}
</SCRIPT>
2. Call method without return values:
The above method can be used. There are at least two other solutions:
<Script language = "JavaScript">
Function gotoservice ()
{
Myframe. src = "http: //.../serverics. asmx? AA "; // you can call your method once.
}
</SCRIPT>
<IFRAME id = "myframe"> </iframe>
Or
Window. Open (Service URI );
Open the mode dialog box.
======================================
I found a reply on the altar, but it is not very clear about the details of the first method. Please be familiar with me and provide the first method for the following simple application situations.Specific parameter settings.
Existing Web service job: datatransfer, where a service named "test" and web method named "test1", returns "Hello, world! ".
Now the test. test1 method is called in JavaScript on the page. "Hello, world!" is displayed! ".
Function btngetdata_onclick ()
{
VaR XMLHTTP = new activexobject ("msxml2.xmlhttp. 4.0 ");
XMLHTTP. Open ("get", "http: // localhost/datatransfer/test. asmx? WSDL ", false ,"","");
XMLHTTP. Send ("");
Form1.txtresults. value = XMLHTTP. responsetext;
}
"Hello, world!" is not returned! ", Please correct myProgram!
Here are:
Http://chs.gotdotnet.com/quickstart/aspplus/