Home > Web Front-end > JS Tutorial > Detailed example code of jQuery Ajax method calling Asp.Net WebService_jquery

Detailed example code of jQuery Ajax method calling Asp.Net WebService_jquery

WBOY
Release: 2016-05-16 18:07:23
Original
1238 people have browsed it

ws.aspx code

Copy code The code is as follows:













jQuery's WebServices call



HelloWorld

Incoming parameters


Return collection


Return composite type


Return DataSet(XML)



The server is processing, please wait.





< /html>

WebService1.asmx.cs
Copy code The code is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System. Data;
namespace jQuery.Learning
{
///
/// Summary description of WebService1
///

[WebService( Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow the use of ASP .NET AJAX To call this web service from a script, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
///
/// No parameters
///

///
[WebMethod]
public string HelloWorld()
{
return "Hello World ";
}
///
/// With parameters
///

///
///
///
///
///
[WebMethod]
public string GetWish(string value1 , string value2, string value3, int value4)
{
return string.Format("Wish you {0}, {1}, {2} in {3} years", value1, value2, value3, value4);
}
///
/// Return collection
///

///
///
[WebMethod]
public List GetArray(int i)
{
List< int> list = new List();
while (i >= 0)
{
list.Add(i--);
}
return list;
}
///
/// Returns a composite type
///

///
[WebMethod]
public Class1 GetClass()
{
return new Class1 { ID = "1", Value = "Good luck in the Year of the Ox" };
}
/// < ;summary>
/// Return XML
///
///
[WebMethod]
public DataSet GetDataSet( )
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
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"] = "All the best";
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
}
}
//Customized class, only two attributes
public class Class1
{
public string ID { get; set; }
public string Value { get; set; }
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template