[ASP.NET] JQuery AJAX usage finishing

Abstract: [ASP.NET] JQuery AJAX usage finishing


There are how many parameters to be used when we re-use Jquery CallBack Server

$.ajax({
                type: "POST",
                url: "MyWebService.asmx/SayHelloJson",
                data: "{ firstName: 'Aidy', lastName: 'F' }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var myData = JSON.parse(data.d);
}
$.ajax({
                type: "POST",
                url: "MyWebService.asmx/SayHello",
                data: "firstName=Aidy&lastName=F", /
                dataType: "text", 
                success: function (data) {
                    $("#searchresultsA").html(data); /
                }
            });

Type: postback to the server, Server to Client will Respon

Url: "? MyWebService.asmx / SayHelloJson firstName = 'aidy' & lastName = 'F'" to indicate the method (Web Service)

[ ""], To get get data into parameters, Server-side can this.comtext.request.quertstring

"MyWebService.ahsx" (generic handler)

"MyWebService.apsx" (General page)

Data: "{firstName: 'Aidy', lastName: 'F'}" parameter passed JSON format is available or "firstName = Aidy & lastName = F"

Server-side with this.comtext.request.From [ ""], to get post data,

Or Web Server will end with Fuction (string firstName, string lastName) to obtain post-funded

contentType: "application / json; charset = utf-8" if it is to transmit data JSON format to make specific mention Server

dataType: "json", "text", "xml", Server return data type

success: function (data) {}: return data with motion

Web Server Code

[WebMethod]
public string SayHello(string firstName, string lastName)
{
    return "Hello " + firstName + " " + lastName;
}
[WebMethod]
public string SayHelloJson(string firstName, string lastName)
{
    var data = new { Greeting = "Hello", Name = firstName + " " + lastName };

    // We are using an anonymous object above, but we could use a typed one too (SayHello class is defined below)
    // SayHello data = new SayHello { Greeting = "Hello", Name = firstName + " " + lastName };

    System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

    return js.Serialize(data);
}

Original: Large column  [ASP.NET] JQuery AJAX usage finishing


Guess you like

Origin www.cnblogs.com/chinatrump/p/11458410.html