When using jquery to implement Ajax in ASP.net, aspx,ashx can be used on the server side, as well as webservice. Recently studied the WebService mode, the jquery Ajax method calls the jquery Ajax method call asp.net WebService Detailed instance code this post gives a very detailed example, but does not give a detailed explanation. There are a few details of the problem began not to pay attention, the cost of the old to adjust the communication:
1) the key field name in the client data data must be strictly consistent with the server-side method parameters.
such as client:
There is a parameter call
$ (document). Ready (function () {
$ ("#btn2"). Click (function () {
$.ajax ({
type: POST),
ContentType: "Application/json",
URL: "Webservice.asmx/getwish",
data: "{value1: ' All things are done ', value2: ' Good luck ', Value3: ' Niu niu Niu, value4:2009} ',
dataType: ' json ',
success:function (Result) {
$ (' #dictionary '). Append ( RESULT.D);}});
Server-side Getwish function arguments must be written as Value1,value2,value3,value4:
[WebMethod]
public string Getwish (string value1, String value2, string value3, int value4)
{return
string. Format ("Wish You in {3} years {0}, {1}, {2}", Value1, value2, Value3, value4);
}
2 The client passes the object to the server-side method:
Client code:
Incoming object
$ (function () {
$ (' #btn6 '). Click (function () {
obj = new Object ();
Obj.id = "1";
Obj. Value = "AAA";
' {' obj ': {' ID ': ' 1 ', Value: ' Horse '}} '
var d = ' {' obj ': ' + json.stringify (obj) + '} ';
$.ajax ({
type: Post), //Access WebService use POST to request
ContentType: "Application/json",//webservice Returns the JSON type
URL: "Webservice.asmx/parmsobject",//Call WebService's address and method name combination----wsurl/method name
data:d, // Here is the parameter to pass, the format is data: "{Paraname:paravalue}", the following will see
dataType: ' json ',
success:function (result) {
alert (RESULT.D);
},
error:function (result) {
alert ("fail");
}
);}
);
Server-side code:
[WebMethod]
public string parmsobject (Class1 obj)
{return
obj.id + ': ' + obj. Value;
}
Debugging Environment: Vs2010+jquery-1.3.2.min.js
The above is a small series for everyone to bring the jquery Ajax WebService transfer parameters of a simple example of all the content, I hope that we support the cloud-Habitat Community ~