JQuery calls WebService implementation code _ jquery

Source: Internet
Author: User
JQuery calls the implementation code of WebService. For more information, see. The following is an example:
1. In aspx:

The Code is as follows:


HelloWorld


Input parameters


Return collection


Return compound type


Return DataSet (XML)


Processing the server. Please wait.




2. In WebService:

The Code is as follows:


[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
// To allow ASP. net ajax to call this Web service from a script, cancel the comments to the downstream.
[System. Web. Script. Services. ScriptService] // If jquery is used to call WebService, cancel the preceding comment.
Public class WebService: System. Web. Services. WebService
{
Public WebService ()
{
// If you use the designed component, uncomment the following line
// InitializeComponent ();
}
[WebMethod]
Public string HelloWorld ()
{
Return "Hello World ";
}
[WebMethod]
Public string GetWish (string value1, string value2, string value3, int value4)
{
Return string. Format ("Wish you {0}, {1}, {2}", value1, value2, value3, value4 in {3} years );
}
[WebMethod]
Public List GetArray (int I)
{
List List = new List ();
While (I> = 0)
{
List. Add (I --);
}
Return list;
}
[WebMethod]
Public Class1 GetClass ()
{
Class1 a = new Class1 ();
A. ID = "1 ";
A. Value = "";
Return;
}
[WebMethod]
Public DataSet GetDataSet ()
{
DataSet ds = new DataSet ();
DataTable dt = new DataTable ("Table1 ");
Dt. Columns. Add ("ID", Type. GetType ("System. String "));
Dt. Columns. Add ("Value", Type. GetType ("System. String "));
DataRow dr = dt. NewRow ();
Dr ["ID"] = "1 ";
Dr ["Value"] = "Happy New Year ";
Dt. Rows. Add (dr );
Dr = dt. NewRow ();
Dr ["ID"] = "2 ";
Dr ["Value"] = "everything goes well ";
Dt. Rows. Add (dr );
Ds. Tables. Add (dt );
Return ds;
}
}
// Custom class with only two attributes
Public class Class1
{
Public string ID {get; set ;}
Public string Value {get; set ;}
}


3. JS:

The Code is as follows:


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.