Jquery Ajax to pass complex parameters to the WebService implementation code _jquery

Source: Internet
Author: User
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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.