<asp:scriptmanager id= "ScriptManager1" runat= "Server" >
<Services>
<asp:servicereference path= "Webservice.asmx"/>
</Services>
</asp:ScriptManager>
——————————————————————————————————————--
-------------------WebService1 -----------------------------
To allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream.
[System.Web.Script.Services.ScriptService]
The method in the webservice is called by the interface by means of a method marked with [WebMethod].
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);
ReturnList;
}
}
--------------------HTMLPage1.Htm-----------------------
<HTML xmlns="Http://www.w3.org/1999/xhtml">
<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",//visit the local WebService service here/can access the HTTP
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>
Calling WebService via Ajax.NET