jQuery Ajax方法调用 Asp.Net WebService 的详细实例代码

高洛峰
풀어 주다: 2017-01-12 14:17:58
원래의
1424명이 탐색했습니다.

ws.aspx 代码 

 
 
 
 
 
 
 

jQuery 的WebServices 调用

HelloWorld
传入参数
返回集合
返回复合类型
返回DataSet(XML)
服务器处理中,请稍后。
로그인 후 복사

WebService1.asmx.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using System.Data; 
namespace jQuery.Learning 
{ 
///  
/// WebService1 的摘要说明 
///  
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 
[System.Web.Script.Services.ScriptService] 
public class WebService1 : System.Web.Services.WebService 
{ 
///  
/// 无参数 
///  
///  
[WebMethod] 
public string HelloWorld() 
{ 
return "Hello World "; 
} 
///  
/// 带参数 
///  
///  
///  
///  
///  
///  
[WebMethod] 
public string GetWish(string value1, string value2, string value3, int value4) 
{ 
return string.Format("祝您在{3}年里 {0}、{1}、{2}", value1, value2, value3, value4); 
} 
///  
/// 返回集合 
///  
///  
///  
[WebMethod] 
public List GetArray(int i) 
{ 
List list = new List(); 
while (i >= 0) 
{ 
list.Add(i--); 
} 
return list; 
} 
///  
/// 返回一个复合类型 
///  
///  
[WebMethod] 
public Class1 GetClass() 
{ 
return new Class1 { ID = "1", Value = "牛年大吉" }; 
} 
///  
/// 返回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"] = "新年快乐"; 
dt.Rows.Add(dr); 
dr = dt.NewRow(); 
dr["ID"] = "2"; 
dr["Value"] = "万事如意"; 
dt.Rows.Add(dr); 
ds.Tables.Add(dt); 
return ds; 
} 
} 
//自定义的类,只有两个属性 
public class Class1 
{ 
public string ID { get; set; } 
public string Value { get; set; } 
} 
}
로그인 후 복사

更多jQuery Ajax方法调用 Asp.Net WebService 的详细实例代码相关文章请关注PHP中文网!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!