.............
.............
thanks to dotnetslackers
.............
Page.aspx
...........
3
4 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
5
6 <div>
7 <input id="name" type="text" />
8 <input id="number" type="text" /><br />
9 <br />
10 <input id="Button1" style="width: 158px" type="button" value="button"
11 language="javascript" />
12 </div>
13
14 </asp:Content>
15 <asp:Content ID="Content3" ContentPlaceHolderID="javascript" runat="server">
16 <script src="../Content/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
17 <script>
18 $(document).ready(function() {
19 $("#Button1").click(function(event) {
20 $.ajax({
21 type: "POST",
22 url: "SimpleService.asmx/SayHelloJson",
23 // Looks like this {'Name': 'Payton', 'Number': '34'} check it in firefox
24 data: "{'Name': '" + $('#name').val() + "', 'Number': '" + $('#number').val() + "'}",
25 contentType: "application/json; charset=utf-8",
26 dataType: "json",
27 success: function(msg) {
28 AjaxSucceeded(msg);
29 },
30 error: AjaxFailed
31 });
32 });
33 });
34 function AjaxSucceeded(result) {
35 alert(result.d);
36 }
37 function AjaxFailed(result) {
38 alert(result.status + ' ' + result.statusText);
39 }
40 </script>
41 </asp:Content>
.............
SimpleService.asmx.cs
.............
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.Services;
6 using System.Web.Services.Protocols;
7
8 namespace Ajax.Web.Public
9 {
10 /// <summary>
11 /// Summary description for SimpleService
12 /// </summary>
13 [WebService(Namespace = "http://tempuri.org/")]
14 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
15 [System.ComponentModel.ToolboxItem(false)]
16 // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
17 [System.Web.Script.Services.ScriptService]
18 public class SimpleService : System.Web.Services.WebService
19 {
28 [WebMethod]
29 public string SayHelloJson(String Name, String Number)
30 {
31 return "Your Name=" + Name + " \nYour Number=" + Number;
32 }
33 }
34 }
.............