2. Calling with simple parameters and simple return values
data : "{name:'Zhang San'}",
dataType: "json",
success: function(json) { alert(json.d); },
error: function(error) {
alert("Calling error" error.responseText ;
Backend WebMethod code:
[WebMethod]
public string SimpleReturns(string name)
{
return String.Format("Your name is {0}", name);
}
Results of debugging with Google:
3. Calling with complex parameters and complex return values
Front-end JS code:
$("#btn3").click(function() {
$. ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "CalledByJquery.asmx/Get StudentList",
data: "{stu ; function(error) {
;
Backend WebMethod:
Copy code
new Student{ID=1,Name="张Three"},
new Student{ID=2,Name="李四"}
since Add(stu);
return studentList;
}
The result of debugging with Google:
4. Calling WebMethod that returns anonymous objects
Front-end JS code:
Copy code
The code is as follows:
$("#btn4").click(function() {
charset=utf -8",
url: "CalledByJquery.asmx/ReturnNoNameClass",
data: "{}",
dataType: "json",
Success: function(json) { alert(json. d); },
error: function(error) {
alert("Calling error" error.responseText);
}
});
});
Backend WebMethod code:
[WebMethod]
public object ReturnNoNameClass()
return new {ID = 1, Name = "Zhang San" }; Result:
Haha, at this point, do you also feel that it is so easy? Mom no longer has to worry about my study. In fact, many things are very simple, but no one Tell us, but we ourselves do not have this need in actual development, so it has caused certain obstacles to our development.
Therefore, communication is so important!