Copy codeThe Code is as follows:
------------------- WebService1 -----------------------------
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
[System. Web. Script. Services. ScriptService]
Public class WebService1: System. Web. Services. WebService
{
[WebMethod]
Public List <string> GetList ()
{
List <string> list = new List <string> ();
List. Add ("Wang Yi ");
List. Add ("22 ");
List. Add ("Hebei ");
Return list;
}
}
--------------------HTMLPage1.htm -----------------------
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script src = "js/Jquery1.7.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ('# Button1'). click (function (){
$. Ajax ({
Type: "post ",
ContentType: "application/json ",
Url: "WebService1.asmx/GetList ",
Data :"{}",
Success: function (result ){
Var str = '';
For (var I = 0; I <result. d. length; I ++ ){
Str + = result. d [I];
}
$ ('# Mydiv'). text (str );
}
})
})
})
</Script>
</Head>
<Body>
<Div id = "mydiv"> </div>
<Input id = "Button1" type = "button" value = "button"/>
</Body>
</Html>