The. Get method of jquery

Source: Internet
Author: User

· Customer class

public class Customer

{

public int Unid {get; set;}

public string CustomerName {get; set;}

public string Memo {get; set;}

public string Other {get; set;}

}

• Server-side processing (JSON_1.ASHX)

Customer customer = new Customer {unid=1,customername= "Song Jiang", memo= "Day Kui xing", other= "black Three Lang"};

String Strjson = Newtonsoft.Json.JsonConvert.SerializeObject (customer);

Context. Response.Write (Strjson);

Jquery.get (URL, [data], [callback], [type])

Can request data over HTTP GET. The callback is an abbreviated application of $.ajax, which is called after the data has been successfully loaded.

(i) ashx file

GET request JSON data

· ASHX file is no longer available

JS

function Getcustomer_ashx () {

$.get (

"Webdata/get_1.ashx",

{},

function (data) {

var tt = "";

$.each (data, function (k, v) {

tt + = k + ":" + V + "<br/>";

})

$ ("#divmessage"). HTML (TT);

},

"JSON"

);

}

Where the parameter is not available, the empty argument list is also preserved, and the data format is set to JSON

(ii) ASHX file, collection

ashx file is no longer available, please see my blog for Other essays

JS

function Getcustomerlist () {

$.get (

"Webdata/get_1.ashx",

{},

function (data) {

var tt = "";

$.each (data, function (k, v) {

$.each (V, function (KK, VV) {

tt + = KK + ":" + vv + "<br/>";

});

});

$ ("#divmessage"). HTML (TT);

},

"JSON"

);

}

Where there are no parameters, the parameter supply part can be empty, can also provide an empty list, the data format can be omitted, write JSON also line, the other several options are also OK.

(iii) Request for a text file

This time get text content, not to JSON object.

function Getcustomer_txt () {

$.get (

"Webdata/get_1.txt",

function (data) {

$ ("#divmessage"). HTML (data);

},

"Text"

);

}

The data types here can be omitted.

(iv) Request WebService

The HTTP GET method requests the Web service, and the default get is closed. To start manually.

You can add get support in the config file:

<webServices>

<protocols>

<add name= "HttpGet"/>

</protocols>

</webServices>

[WebMethod]

public string GetCustomer ()

{

Customer customer = new Customer

{Unid = 1, CustomerName = "Song Jiang", Memo = "Day Kui xing", other = "Black Three Lang"};

String Strjson = Newtonsoft.Json.JsonConvert.SerializeObject (customer);

return Strjson;

}

The Scriptmethod property label is used to specify the HTTP verb to invoke the method and the format of the response. This property is used to specify information about the methods that can be called from client script. Use this property to specify an HTTP verb (GET or POST) that can be used to invoke a method. It also allows you to specify whether you want to format the response using JavaScript object Symbols (JSON) or XML.

· Usehttpget

Specifies whether to invoke the method by using the HTTP GET command. The default value is False.

· Responseformat

Specifies whether the response is serialized as JSON or XML. The default value is Json. When a method returns an XmlDocument or XmlElement object, the Responseformat property can be used to specify the XML as the return type.

· Xmlserializestring

Specifies whether all return types, including string types, are serialized as XML. When the response is serialized as JSON, the value of the Xmlserializestring property is ignored.

If the Web service method does not decorate this tag, it is serialized as a JSON object by default.

function Getcustomer_webservice () {

$.get (

"Get_1.asmx/getcustomer",

function (data) {

var jsonobject = $.jsontoobject (Data.text);

var tt = ';

$.each (Jsonobject, function (k, v) {

tt + = k + ":" + V + "<br/>";

});

$ ("#divmessage"). HTML (TT);

},

"JSON"

);}

This is the example that has been raised so far. When Ajax get requests the Web service, be aware of the get protocol access.

The. Get method of jquery

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.