Copy Code code as follows:
-------------------WebService1-----------------------------
To allow the use of ASP.net AJAX to invoke this Web service from a script, uncomment the downlink.
[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-----------------------
<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>
<body>
<div id= "Mydiv" ></div>
<input id= "Button1" type= "button" value= "button"/>
</body>