Entity:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Runtime.Serialization;
Namespace Entity
{
[DataContract]
public class User
{
[DataMember]
public string Name
{
Get
Set
}
[DataMember]
public int Age
{
Get
Set
}
}
}
WebService:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Services;
Using Entity;
Namespace Jquery.handler
{
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[System.ComponentModel.ToolboxItem (False)]
[System.Web.Script.Services.ScriptService]
public class UserService1:System.Web.Services.WebService
{
[WebMethod]
public string ComplexType (User hero,list<user> users)
{
Return hero. Name + "has" + users. Count + "people!";
}
}
}
Html:
Copy Code code as follows:
& lt;title>ajax</title>
<script src= ". /scripts/jquery-1.6.min.js "type=" Text/javascript "></script>
<script type=" Text/javascript ">
$ (function () {
$ ("#btnWeb"). Click (function () {
$.ajax (
{
Type: Post,
URL: ...). /handler/userservice.asmx/complextype ",
DataType:" JSON ",
ContentType:" Application/json ",
Data: ' {' Hero ': {' name ': ' Zhoulq ', ' age ': ' users ': [{' Name ': ' Zhangs ', ' age ': 22},{' name ': ' Wangw ', ' age ': 26},{' name ': ' Liuj ', ' age ":",
{"Name": "Luos", "Age":}]} ',
Success:function (data) {$ (' #web '). Text (DATA.D);
});
});
});
</script>
<body>
<input id= "btnweb" type= "button" value= "Request WebService" /><label id= "web" ></label>
</body>